812加密算法是一款正在发展中的算法,期盼密码专家、剥皮厅长老、去壳大侠、丐帮帮主、长舌巫女、笑话爱好者前来指点一二。老生这厢有礼了。
算法包含在下面的控制台小程序里。
运行方式
加密:
XXXX 被加密文件名 密码 1
解密:
XXXX 被解密文件名 密码 -1
注意:密码不得小于10个字节。
将下面的东西,拷贝到XXXX.CPP 或 XXXX.C 编译即可 用VC C-Free 集成编译器都可以,别的没试过。
/////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
static int s1=1;
static int s2=1;
#define MODMULT(a,b,m,s) s= b*s; if(s<0) s+=m;
unsigned int combinedLOG(void);
void initLOG(int InitS1,int InitS2);
void HanShu(char *filename,char *mima,int biaozhi); //加密解密函数
//==================================================函数及变量定义
unsigned int x_ = 1,
y_ = 1,
z_ = 1,
c_ = 1;
unsigned int Rand(); //来自网George Marsaglia造 周期2的124次方 = 2.1×10的37次方
//==================================================函数及变量定义
int main(void)
{
char filename[240],mima[240];
int biaozhi;
printf("请输入被加密文件名 密码 标志 : ");
scanf("%s %s %d" ,&filename,&mima,&biaozhi);
//HanShu是加密解密函数 biaozhi=1 加密 biaozhi=-1 解密
HanShu(filename,mima,biaozhi);
getch(); //暂停
return 0;
}
void HanShu(char *filename,char *mima,int biaozhi)
{
unsigned int K[100]={0}; //密码相关参数
FILE *f;
unsigned char *ss; //文件容器
unsigned char *ss1; //密钥容器
unsigned char ch;
unsigned char ch1='\0';
unsigned char ss_my[256] ={
0x4f,0x1d,0x03,0xc7,0xa2,0x0d,0xd7,0xbb,0xd9,0x17,0x33,0x19,0x82,0xbf,0x9d,0x4a,0x2a,
0x51,0xe4,0x2e,0x9a,0x47,0xd4,0x3e,0x2b,0x59,0x43,0xc2,0xc9,0x92,0x00,0x07,0xf7,0xa3,
0x2c,0x10,0xc0,0x97,0xa7,0x1f,0x55,0x1c,0x21,0x49,0x58,0xa0,0xd2,0x0e,0x13,0x40,0x6c,
0xe6,0x22,0xdd,0x05,0x08,0x75,0xc6,0xd8,0x7a,0xcc,0x8d,0x37,0x70,0x8c,0x72,0x32,0x28,
0x53,0x6f,0x30,0x7b,0x80,0x6b,0x62,0xd0,0xec,0x9b,0x61,0xb9,0x52,0x93,0x74,0xb4,0xf2,
0xa9,0xe1,0x06,0xbd,0x41,0xcb,0x7f,0x36,0x25,0x35,0x46,0x77,0x54,0x73,0xf6,0x85,0x1a,
0xf0,0x26,0xb3,0x6e,0xac,0xf4,0xe2,0x90,0x88,0xce,0x71,0xcd,0x9c,0x09,0x18,0x9f,0x38,
0xb6,0x86,0x69,0xfd,0xde,0x99,0x57,0x76,0xee,0xb1,0x01,0xa8,0xd1,0x39,0x02,0x4c,0xfc,
0x94,0xef,0x7d,0x3b,0x48,0xc1,0x7e,0x24,0x15,0x5a,0x3d,0xc8,0x0b,0xaa,0x83,0x29,0xa6,
0x5d,0xe3,0x14,0x67,0xa5,0x23,0xbe,0x11,0xe5,0xab,0x79,0xda,0x8b,0xe9,0x44,0x1e,0xc3,
0xc4,0x95,0x84,0xbc,0xf9,0xcf,0x42,0xfe,0x2d,0x68,0xae,0x64,0xb0,0x04,0x16,0x4d,0x5b,
0x31,0x34,0xdb,0x0f,0x8f,0x0c,0x3c,0xf5,0xe0,0xb5,0x66,0xd6,0x5e,0x65,0xad,0x60,0xd3,
0x12,0x20,0x2f,0x87,0x6d,0x3a,0xd5,0x8e,0xb7,0x5c,0x5f,0x4e,0xf1,0xeb,0xc5,0x96,0x63,
0xdf,0xdc,0xe8,0xff,0x45,0x27,0x1b,0x4b,0xca,0x81,0x8a,0x89,0x78,0xaf,0x6a,0xfb,0x9e,
0x98,0xba,0x56,0xf8,0xa1,0x0a,0xb2,0xa4,0xb8,0x91,0xed,0x7c,0xea,0xf3,0x3f,0x50,0xe7,
0xfa};
int b256=256;
int Length=0;
int i,j=0;
if((f=fopen(filename,"ab+"))==NULL)
{printf("无法打开1");exit(0);}
Length = filelength(_fileno(f)); //得到文件长度
fclose(f);
ss=new unsigned char[Length+256+1]; //文件容器
ss1=new unsigned char[Length+256+1]; //密钥容器
ss = (unsigned char*)calloc(Length+256, sizeof(char));
ss1 = (unsigned char*)calloc(Length+256, sizeof(char));
int k1=strlen(mima); //k1密码串长度
if(k1<10) exit(0);
x_ = (mima[0]+mima[9])*mima[4]*mima[0]*mima[4];
y_ = (mima[1]+mima[8])*mima[5]*mima[1]*mima[5];
z_ = (mima[2]+mima[7])*mima[5]*mima[2]*mima[6];
c_ = (mima[3]+mima[6])*mima[4]*mima[3]*mima[7];
initLOG(Rand(),Rand()); //combinedLOG()种子设定
for(i=0;i<100;i++)
{
x_ = combinedLOG();
y_ = combinedLOG();
z_ = combinedLOG();
c_ = combinedLOG();
initLOG(Rand(),Rand());
if(K[i]!=0) K[i]=(K[i]>>(x_%7)); //采用数据截断舍弃防止跟踪
K[i] = K[i] + Rand() + combinedLOG();
}
if((f=fopen(filename,"ab+"))==NULL)
{printf("无法打开2");exit(0);}
fseek(f,0,0);
fread(ss,Length,1,f); //文件内容读入 ss
fclose(f);
//=================数据处理函数Q
x_ = K[31];
y_ = K[73];
z_ = K[47];
c_ = K[91];
for(i=0;i<Length;i=i+b256) //结果串
{
for(j=0;j<b256;j++) //单元串随机排序
{
int n1=Rand()%b256;
ch=ss_my[j];
ss_my[j]=ss_my[n1];
ss_my[n1]=ch;
ss_my[j]=ss_my[j]+combinedLOG()%123;
}
for(j=0;j<b256;j++)
{
ss1[i+j]=ss1[i+j]+ss_my[j]; //对结果串赋值
}
}
for(i=0;i<Length;i++) //结果串
{
ss[i] = ss[i] + biaozhi*ss1[i]; //加密解密
}
ss1[Length]='\0';
ss[Length]='\0';
if((f=fopen(filename,"w"))==NULL)
{printf("无法打开3");exit(0);}
fclose(f);
if((f=fopen(filename,"ab+"))==NULL)
{printf("无法打开4");exit(0);}
fseek(f,0,SEEK_SET);
fwrite(ss,Length,1,f);
fclose(f);
delete [] ss;
delete [] ss1;
}
unsigned int combinedLOG(void)
{
unsigned int z;
MODMULT(40014,12211,2147483563,s1)
MODMULT(40692,3791,2147483399,s2)
z = s1 -s2;
return z;
}
void initLOG(int InitS1,int InitS2)
{
s1=InitS1;
s2=InitS2;
}
unsigned int Rand()
{
// unsigned long long t, A = 698769069LL; //原型
// 它采用了三种随机算法混合而成,“线性同余”,“移位轮转”和“带记忆乘法”,
// unsigned long t, A = 698769069L;
unsigned __int64 t,A = 698769069L;
x_ = 69069*x_+12345;
y_ ^= (y_<<13); y_ ^= (y_>>17); y_ ^= (y_<<5);
t = A*z_ + c_; c_ = (unsigned int)(t >> 32);
return x_+y_+(z_=(unsigned int)t);
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课