几个问题问问大大们

yize.link 2009-03-22 12:09:39
你好,首先 我已经阅读过提问的智慧。

以下是互联网搜索不到的结果 【或许是我不懂的搜索】



失礼了,请问:


1、memcpy (bytes+insert, v, len); 返回的结果将会是什么呢?



第二,我想做一个 send 和 recv 的程序。 我想把数据包弄成 string 格式的。

例如要发送 headle 和 string1 string2 int1 int2 这样多数据的结构,然后用DES加密,应该用什么方式来分开这些数据呢?
我自己暂时想了一个方法,就是 headle|||string1||| 这样的方式来区分出数据,但是 其中怎么判断 ||| 从而来分解出正确的数据出来呢? 请教了。

请问还有更好的方法吗?


第三,DES加密后,进行解密,得到的是不是原件?

send的数据用DES加密适合吗?
...全文
114 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hi_tech 2009-03-25
  • 打赏
  • 举报
回复
怎么加密呀文件
yize.link 2009-03-22
  • 打赏
  • 举报
回复
感谢二楼的朋友。 你的提示让我联想到了一个方法,不知道效率如何,还得多加学习
oyljerry 2009-03-22
  • 打赏
  • 举报
回复
2.对于有string这种类型,你可以定一个字段int nLength来表示这个数据包的数据有多大,然后接受后知道有多大的数据来处理
3.DES加密后,解密得到的数据就是原来的,只要数据在传输中发生了损坏等,一般TCP等有crc,发现数据坏了,会重发
yubuhuifei 2009-03-22
  • 打赏
  • 举报
回复
1、memcpy (bytes+insert, v, len); 返回的结果将会是什么呢?
[Reply] 在内存区,把‘bytes+insert’ 的前'len'位设置为'v',其中v是整形。可参考memcpy的定义;


第二,我想做一个 send 和 recv 的程序。 我想把数据包弄成 string 格式的。

例如要发送 headle 和 string1 string2 int1 int2 这样多数据的结构,然后用DES加密,应该用什么方式来分开这些数据呢?
我自己暂时想了一个方法,就是 headle|||string1||| 这样的方式来区分出数据,但是 其中怎么判断 ||| 从而来分解出正确的数据出来呢? 请教了。

请问还有更好的方法吗?
[Reply]不明白你的意图。

第三,DES加密后,进行解密,得到的是不是原件?
[Reply] 这要取决于加密算法与解密算法是否对称。对于成熟的DES而言,你只要拿去用就行了,应该不存在问题。
1900_in_bj 2009-03-22
  • 打赏
  • 举报
回复
楼主可以查一下BER编码规范。
如果楼主有时间的话,学一下ans.1,那是标准的网络包定义语言和传输语法。
asn1c是开源的asn编译器,可以直接编译生成BER编码的源程序。
baihacker 2009-03-22
  • 打赏
  • 举报
回复
Copies bytes between buffers. More secure versions of these functions are available; see memcpy_s, wmemcpy_s.


void *memcpy(
void *dest,
const void *src,
size_t count
);
wchar_t *wmemcpy(
wchar_t *dest,
const wchar_t *src,
size_t count
);


Parameters
dest
New buffer.

src
Buffer to copy from.

count
Number of characters to copy.

Return Value
The value of dest.

Remarks
memcpy copies count bytes from src to dest; wmemcpy copies count wide characters (two bytes). If the source and destination overlap, the behavior of memcpy is undefined. Use memmove to handle overlapping regions.

Security Note Make sure that the destination buffer is the same size or larger than the source buffer. For more information, see Avoiding Buffer Overruns.

The memcpy and wmemcpy functions will only be deprecated if the constant _CRT_SECURE_DEPRECATE_MEMORY is defined prior to the inclusion statement in order for the functions to be deprecated, such as in the example below:

Copy Code
#define _CRT_SECURE_DEPRECATE_MEMORY
#include <memory.h>


or

Copy Code
#define _CRT_SECURE_DEPRECATE_MEMORY
#include <wchar.h>


Requirements
Routine
Required header

memcpy
<memory.h> or <string.h>

wmemcpy
<wchar.h>


For additional compatibility information, see Compatibility in the Introduction.

Example
See memmove for a sample of how to use memcpy.

See Also

64,652

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧