随机数算法加解密的程序源码
本帖最后由 Joduska 于 2019-7-4 10:34 编辑使用方法
加密:OneBitOneCypher plaintext cyphertext password
解密:OneBitOneCypher cyphertext plaintext password
*/
#include <stdio.h>
#include <stdlib.h>
// struct stat 结构的头文件。
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
// 取明文/密文的文件大小。
struct stat statFileSize;
stat(argv, &statFileSize);
unsigned long ulFileSize = statFileSize.st_size;
unsigned char *pucPlaintext_Cyphertext = malloc(ulFileSize);
// 取明文/密文的文件描述符。
unsigned long ulPlaintext_CyphertextFD = open(argv, O_RDONLY, S_IRUSR | S_IWUSR);
unsigned long ulCyphertext_PlaintextFD = open(argv, O_CREAT | O_WRONLY, S_IREAD | S_IWRITE);
// read API。
read(ulPlaintext_CyphertextFD, pucPlaintext_Cyphertext, ulFileSize);
// 至少8个字符的密码(包括空格)
unsigned char aucKeyTable, aucPassword;
unsigned long i, j;
for(i = 0; i < 256; ++i)
{
Loop:
aucKeyTable = rand() & 255;
for(j = 0; j < i; ++j)
{
if(aucKeyTable == aucKeyTable)
{
goto Loop;
}
}
}
for(i = 0; argv; ++i)
{
aucPassword = argv;
}
srand(*((unsigned int*)aucPassword) % RAND_MAX);
for(j = 0; j < ulFileSize; j += 256)
{
unsigned long k, l, ulTablePosition;
for(k = 0; k < i; ++k)
{
ulTablePosition = aucPassword % 256;
aucPassword = aucKeyTable;
}
if(!(j /256 % 2))
{
unsigned long *pulKeySwap1 = (unsigned long*)aucKeyTable, *pulKeySwap2 = (unsigned long*)aucKeyTable, ulKeyTemp;
for(l = 0; l < 32; ++l)
{
ulTablePosition = aucPassword % 32;
if(l != ulTablePosition)
{
ulKeyTemp = pulKeySwap1;
pulKeySwap1 = pulKeySwap2;
pulKeySwap2 = ulKeyTemp;
}
}
}
else
{
for(k = 0; k < 256; ++k)
{
ulTablePosition = rand() % 256;
if(k != ulTablePosition)
{
aucKeyTable += aucKeyTable;
aucKeyTable = aucKeyTable - aucKeyTable;
aucKeyTable -= aucKeyTable;
}
}
}
for(l = 0; l < 256; ++l)
{
pucPlaintext_Cyphertext ^= aucKeyTable;
}
}
write(ulCyphertext_PlaintextFD, pucPlaintext_Cyphertext, ulFileSize);
return 0;
}
方法并不适用!只是分析出来给大家解密的! 谢谢楼主热心分享 楼主写的很好,很精辟 shangziq 发表于 2019-7-4 11:00
楼主写的很好,很精辟
看到你的头像还以为是lcg该回复了我。 学习一下加密过程 看样子很6666
页:
[1]