标签:int sizeof ret 原创 eof 产生 ring net and
之前要加密密码的时候,要加入盐值以加强强度,找了部分,又在网上的基础上修改了下(参考网页:http://blog.csdn.net/wangchangshuai0010/article/details/17188417)
//产生长度为length的随机字符串
char pSymbol[] = {‘~‘,‘`‘,‘!‘,‘@‘,‘#‘,‘$‘,‘%‘,‘^‘,‘&‘,
‘*‘,‘(‘,‘)‘,‘_‘,‘+‘,‘-‘,‘=‘,‘{‘,‘}‘,‘|‘,‘[‘,‘]‘,
‘:‘,‘;‘,‘<‘,‘>‘,‘?‘,
‘,‘,‘.‘,‘\"‘,‘\\‘,‘\‘‘,‘/‘};
char* getRandomString(int length) { int nRand, i; char* string; srand((unsigned) time(NULL )); if ((string = (char*) malloc(length + 1)) == NULL ) return NULL ; for (i = 0; i < length; i++) { nRand = rand() % (sizeof(pSymbol) + 26 * 2 + 10); if (nRand >= 0) { if (nRand < 26) string[i] = ‘A‘ + nRand; else if (nRand < 52) string[i] = ‘a‘ + nRand - 26; else if (nRand < 62) string[i] = ‘a‘ + nRand - 52; else if(nRand - 62 < sizeof(pSymbol)) string[i] = pSymbol[nRand - 62]; else string[i] = ‘x‘; } else string[i] = ‘x‘; } string[length] = ‘\0‘; return string; }
标签:int sizeof ret 原创 eof 产生 ring net and
原文地址:http://www.cnblogs.com/lydit/p/7279428.html