|
[求助]爆破XTEA的KEY
ANSI C void encipher(unsigned long *const v,unsigned long *const w, const unsigned long *const k) { register unsigned long y=v[0],z=v[1],sum=0,delta=0x9E3779B9, a=k[0],b=k[1],c=k[2],d=k[3],n=32; while(n-->0) { sum += delta; y += (z << 4)+a ^ z+sum ^ (z >> 5)+b; z += (y << 4)+c ^ y+sum ^ (y >> 5)+d; } w[0]=y; w[1]=z; } void decipher(unsigned long *const v,unsigned long *const w, const unsigned long *const k) { register unsigned long y=v[0],z=v[1],sum=0xC6EF3720, delta=0x9E3779B9,a=k[0],b=k[1], c=k[2],d=k[3],n=32; /* sum = delta<<5, in general sum = delta * n */ while(n-->0) { z -= (y << 4)+c ^ y+sum ^ (y >> 5)+d; y -= (z << 4)+a ^ z+sum ^ (z >> 5)+b; sum -= delta; } w[0]=y; w[1]=z; } |
|
[求助]爆破XTEA的KEY
xtea.c /* LibTomCrypt, modular cryptographic library -- Tom St Denis * * LibTomCrypt is a library that provides various cryptographic * algorithms in a highly modular and flexible manner. * * The library is free for all purposes without any express * guarantee it works. * * Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org */ #include "mycrypt.h" #ifdef XTEA const struct _cipher_descriptor xtea_desc = { "xtea", 1, 16, 16, 8, 32, &xtea_setup, &xtea_ecb_encrypt, &xtea_ecb_decrypt, &xtea_test, &xtea_keysize }; int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey) { unsigned long x, sum, K[4]; _ARGCHK(key != NULL); _ARGCHK(skey != NULL); /* check arguments */ if (keylen != 16) { return CRYPT_INVALID_KEYSIZE; } if (num_rounds != 0 && num_rounds != 32) { return CRYPT_INVALID_ROUNDS; } /* load key */ LOAD32L(K[0], key+0); LOAD32L(K[1], key+4); LOAD32L(K[2], key+8); LOAD32L(K[3], key+12); for (x = sum = 0; x < 32; x++) { skey->xtea.A[x] = (sum + K[sum&3]) & 0xFFFFFFFFUL; sum = (sum + 0x9E3779B9UL) & 0xFFFFFFFFUL; skey->xtea.B[x] = (sum + K[(sum>>11)&3]) & 0xFFFFFFFFUL; } #ifdef CLEAN_STACK zeromem(&K, sizeof(K)); #endif return CRYPT_OK; } void xtea_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *key) { unsigned long y, z; int r; _ARGCHK(pt != NULL); _ARGCHK(ct != NULL); _ARGCHK(key != NULL); LOAD32L(y, &pt[0]); LOAD32L(z, &pt[4]); for (r = 0; r < 32; r += 4) { y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r])) & 0xFFFFFFFFUL; z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r])) & 0xFFFFFFFFUL; y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r+1])) & 0xFFFFFFFFUL; z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r+1])) & 0xFFFFFFFFUL; y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r+2])) & 0xFFFFFFFFUL; z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r+2])) & 0xFFFFFFFFUL; y = (y + ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r+3])) & 0xFFFFFFFFUL; z = (z + ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r+3])) & 0xFFFFFFFFUL; } STORE32L(y, &ct[0]); STORE32L(z, &ct[4]); } void xtea_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *key) { unsigned long y, z; int r; _ARGCHK(pt != NULL); _ARGCHK(ct != NULL); _ARGCHK(key != NULL); LOAD32L(y, &ct[0]); LOAD32L(z, &ct[4]); for (r = 31; r >= 0; r -= 4) { z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r])) & 0xFFFFFFFFUL; y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r])) & 0xFFFFFFFFUL; z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r-1])) & 0xFFFFFFFFUL; y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r-1])) & 0xFFFFFFFFUL; z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r-2])) & 0xFFFFFFFFUL; y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r-2])) & 0xFFFFFFFFUL; z = (z - ((((y<<4)^(y>>5)) + y) ^ key->xtea.B[r-3])) & 0xFFFFFFFFUL; y = (y - ((((z<<4)^(z>>5)) + z) ^ key->xtea.A[r-3])) & 0xFFFFFFFFUL; } STORE32L(y, &pt[0]); STORE32L(z, &pt[4]); } int xtea_test(void) { #ifndef LTC_TEST return CRYPT_NOP; #else static const unsigned char key[16] = { 0x78, 0x56, 0x34, 0x12, 0xf0, 0xcd, 0xcb, 0x9a, 0x48, 0x37, 0x26, 0x15, 0xc0, 0xbf, 0xae, 0x9d }; static const unsigned char pt[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; static const unsigned char ct[8] = { 0x75, 0xd7, 0xc5, 0xbf, 0xcf, 0x58, 0xc9, 0x3f }; unsigned char tmp[2][8]; symmetric_key skey; int err, y; if ((err = xtea_setup(key, 16, 0, &skey)) != CRYPT_OK) { return err; } xtea_ecb_encrypt(pt, tmp[0], &skey); xtea_ecb_decrypt(tmp[0], tmp[1], &skey); if (memcmp(tmp[0], ct, 8) != 0 || memcmp(tmp[1], pt, 8) != 0) { return CRYPT_FAIL_TESTVECTOR; } /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ for (y = 0; y < 8; y++) tmp[0][y] = 0; for (y = 0; y < 1000; y++) xtea_ecb_encrypt(tmp[0], tmp[0], &skey); for (y = 0; y < 1000; y++) xtea_ecb_decrypt(tmp[0], tmp[0], &skey); for (y = 0; y < 8; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR; return CRYPT_OK; #endif } int xtea_keysize(int *desired_keysize) { _ARGCHK(desired_keysize != NULL); if (*desired_keysize < 16) { return CRYPT_INVALID_KEYSIZE; } *desired_keysize = 16; return CRYPT_OK; } #endif Source from http://www.koders.com/c/fid97A9E9DC3E5AC3A084FEC06203AF3B58F4909658.aspx?s=rsa |
|
|
|
[分享]真是利害。
她已經講了啊,我猜就是這兩間的其中一間了。 |
|
[求助]RSA C算法实现
MAIN.CPP # include <iostream.h> # include <string.h> # include <fstream.h> # include <math.h> # include <stdio.h> # include <conio.h> # include <stdlib.h> # define ul unsigned long ul isPrime(ul n) { ul b=1; for(ul i=2;i<n;i++) if(n%i==0) { b=0; break; } return b; } ul Power(ul x,ul y) { ul ans=1; if(x==1) return x; for(ul i=1;i<=y;i++) ans*=x; return(ans); } char * ToBin(int x) { char *ans=new char[20]; int i=0; while(x>=1) { if(x%2==1) ans[i]='1'; else ans[i]='0'; x/=2; i++; } if(x==1) ans[i]='1',i++; ans[i]='\0'; strrev(ans); return(ans); } ul Crypt(int x,int key,int n) // (x^y)%z //Method 2 { char *B=new char[20]; B=ToBin(key); ul ans=1;int c=1; for(int i=0;i<strlen(B);i++) { c=2*c; ans=(ans*ans)%n; if(B[i]=='1') { c=c+1; ans=(ans*x)%n; } } return(ans); } void Fun1(int,int,int); int Bin2Num(char *s) { int ans=0; int i,j; for(j=0,i=7;i>=0;j++,i--) { if(s[i]=='1') ans+=Power(2,j); } return ans; } char * Num2Bin(int n) { char *s=new char[20]; int i=0; for(i=0;i<8;i++) s[i]='0'; while(n>1) { if(n%2==1) s[i]='1'; else s[i]='0'; n/=2; i++; } if(n%2==1) s[i]='1'; else s[i]='0'; s[8]='\0'; strrev(s); return s; } void KeyEnc(int,int); void KeyDec(int,int); void main() { clrscr(); randomize(); /* K E Y G E N E R A T I O N */ ul p,q,n,n1,e,d; Beg: // Reading 2 random prime-numbers from 20 to 50 p=2+rand()%200; q=2+rand()%200; //p=17;q=11; if(p==q||!isPrime(p)||!isPrime(q)) goto Beg; n = p * q; n1 = (p-1) * (q-1); int x=n1+1; for(e=2;e<=x/2;e++) { if(x%e==0) break; } d=x/e; if(p==1||q==1||e==1||d==1||e==d|| q==e||q==d||p==e||p==d) goto Beg; // if(e>30||d>30) goto Beg; ul P1=18,P2,Cypher; B1: Cypher=Crypt(P1,e,n); //Encrypting using public-key 'e' // if(Cypher>160||Cypher<d*2||Cypher==P1) goto Beg; P2=Crypt(Cypher,d,n);//Decrypting using private key 'd' cout<<"p = "<<p<<endl; cout<<"q = "<<q<<endl; cout<<"n =(p*q) = "<<n<<endl; cout<<"n1=(p-1)*(q-1)= "<<n1<<endl; cout<<"e = "<<e<<endl; cout<<"d = "<<d<<endl<<endl; cout<<"Public Key : { "<<e<<","<<n<<" }"<<endl; cout<<"Private Key : { "<<d<<","<<n<<" }"<<endl; cout<<"PlainText Before Encryption is : "<<P1<<endl; cout<<"Cypher is : "<<Cypher<<endl; cout<<"PlainText After Decryption is : "<<P2<<endl; getch(); randomize(); clrscr();goto Beg; // KeyEnc(e,n); // KeyDec(d,n); getch(); } void KeyEnc(int e,int n) { ifstream fin("key.txt"); ofstream fout("keyEnc.txt"); char str[10]; int i,X,Y,j; //while(!fin.eof()) for(j=0;j<8;j++) { for(i=0;i<8&&!fin.eof();i++) { fin.get(str[i]); cout<<str[i]; } str[8]='\0'; cout<<str<<","; X=Bin2Num(str); Y=Crypt(X,e,n); cout<<X<<","<<Y<<endl; fout<<Y<<endl; getch(); } fin.close(); fout.close(); } void KeyDec(int d,int n) { ifstream fin("keyEnc.txt"); ofstream fout("keyDec.txt"); char ch; int i,X,Y; char *str=new char[20]; cout<<"Decrypt...\n"; int Ch; while(!fin.eof()) { fin>>Ch; if(fin.eof()) return; cout<<Ch; Y=Crypt(Ch,d,n); cout<<","<<Y; str=Num2Bin((int)Y); cout<<","<<str<<endl; fout<<str; getch(); } fin.close(); fout.close(); } void Fun1(int e,int d,int n) { char str[30]; cout<<"Enter some Text : "; gets(str); ofstream fout("d:\\cyfer.txt",ios::binary); int M,C; char ch; for(int i=0;i<strlen(str);i++) { C=Crypt(str[i],e,n); fout.put(C); } fout.close(); ifstream fin("d:\\cyfer.txt"); while(!fin.eof()) { fin.get(ch); ch=Crypt(ch,d,n); cout<<ch; } fin.close(); } RSA1.CPP # include <iostream.h> # include <string.h> # include <fstream.h> # include <math.h> # include <stdio.h> # include <conio.h> # include <stdlib.h> # define ul unsigned long ul isPrime(ul n) { ul b=1; for(ul i=2;i<n;i++) if(n%i==0) { b=0; break; } return b; } ul Power(ul x,ul y) { ul ans=1; if(x==1) return x; for(ul i=1;i<=y;i++) ans*=x; return(ans); } char * ToBin(int x) { char *ans=new char[20]; int i=0; while(x>=1) { if(x%2==1) ans[i]='1'; else ans[i]='0'; x/=2; i++; } if(x==1) ans[i]='1',i++; ans[i]='\0'; strrev(ans); return(ans); } ul Crypt(int x,int key,int n) // (x^y)%z //Method 2 { char *B=new char[20]; B=ToBin(key); ul ans=1; int c=1; for(ul i=0;i<strlen(B);i++) { c=2*c; ans=(ans*ans)%n; if(B[i]=='1') { c=c+1; ans=(ans*x)%n; } } return(ans); } void main() { clrscr(); randomize(); /* K E Y G E N E R A T I O N */ ul p,q,n,n1,e,d; Beg: // Reading 2 random prime-numbers from 20 to 50 p=2+rand()%200; q=2+rand()%200; if(p==q||!isPrime(p)||!isPrime(q)) goto Beg; n = p * q; n1 = (p-1) * (q-1); ul x=n1+1; for(e=2;e<=x/2;e++) { if(x%e==0) break; } d=x/e; if(p==1||q==1||e==1||d==1||e==d|| q==e||q==d||p==e||p==d) goto Beg; ul P1=31,P2,Cypher; B1: Cypher=Crypt(P1,e,n); //Encrypting using public-key 'e' P2=Crypt(Cypher,d,n);//Decrypting using private key 'd' cout<<"p = "<<p<<endl; cout<<"q = "<<q<<endl; cout<<"n =(p*q) = "<<n<<endl; cout<<"n1=(p-1)*(q-1)= "<<n1<<endl; cout<<"e = "<<e<<endl; cout<<"d = "<<d<<endl<<endl; cout<<"Public Key : { "<<e<<","<<n<<" }"<<endl; cout<<"Private Key : { "<<d<<","<<n<<" }"<<endl; cout<<"PlainText Before Encryption is : "<<P1<<endl; cout<<"Cypher is : "<<Cypher<<endl; cout<<"PlainText After Decryption is : "<<P2<<endl; getch(); randomize(); clrscr();goto Beg; getch(); } RSA2.CPP # include <iostream.h> # include <string.h> # include <fstream.h> # include <math.h> # include <stdio.h> # include <conio.h> # include <stdlib.h> # define ul unsigned long ul isPrime(ul n) { ul b=1; for(ul i=2;i<n;i++) if(n%i==0) { b=0; break; } return b; } ul Power(ul x,ul y) { ul ans=1; if(x==1) return x; for(ul i=1;i<=y;i++) ans*=x; return(ans); } char * ToBin(int x) { char *ans=new char[20]; int i=0; while(x>=1) { if(x%2==1) ans[i]='1'; else ans[i]='0'; x/=2; i++; } if(x==1) ans[i]='1',i++; ans[i]='\0'; strrev(ans); return(ans); } ul Crypt(int x,int key,int n) // (x^y)%z //Method 2 { char *B=new char[20]; B=ToBin(key); ul ans=1;int c=1; for(int i=0;i<strlen(B);i++) { c=2*c; ans=(ans*ans)%n; if(B[i]=='1') { c=c+1; ans=(ans*x)%n; } } return(ans); } void Fun1(int,int,int); int Bin2Num(char *s) { int ans=0; int i,j; for(j=0,i=7;i>=0;j++,i--) { if(s[i]=='1') ans+=Power(2,j); } return ans; } char * Num2Bin(int n) { char *s=new char[20]; int i; for(i=0;i<8;i++) s[i]='0'; i=0; while(n>1) { if(n%2==1) s[i]='1'; else s[i]='0'; n/=2; i++; } if(n%2==1) s[i]='1'; else s[i]='0'; s[8]='\0'; strrev(s); return s; } void KeyEnc(int,int); void KeyDec(int,int); void main() { clrscr(); randomize(); /* K E Y G E N E R A T I O N */ ul p,q,n,n1,e,d; Beg: // Reading 2 random prime-numbers from 20 to 50 p=2+rand()%150; q=2+rand()%150; if(p==q||!isPrime(p)||!isPrime(q)) goto Beg; n = p * q; n1 = (p-1) * (q-1); int x=n1+1; for(e=2;e<=x/2;e++) { if(x%e==0) break; } d=x/e; if(p==1||q==1||e==1||d==1||e==d|| q==e||q==d||p==e||p==d) goto Beg; ul P1=18,P2,Cypher; B1: Cypher=Crypt(P1,e,n); //Encrypting using public-key 'e' P2=Crypt(Cypher,d,n);//Decrypting using private key 'd' cout<<"p = "<<p<<endl; cout<<"q = "<<q<<endl; cout<<"n =(p*q) = "<<n<<endl; cout<<"n1=(p-1)*(q-1)= "<<n1<<endl; cout<<"e = "<<e<<endl; cout<<"d = "<<d<<endl<<endl; cout<<"Public Key : { "<<e<<","<<n<<" }"<<endl; cout<<"Private Key : { "<<d<<","<<n<<" }"<<endl; cout<<"PlainText Before Encryption is : "<<P1<<endl; cout<<"Cypher is : "<<Cypher<<endl; cout<<"PlainText After Decryption is : "<<P2<<endl; cout<<"\n\n\nEncrypting Key..."; cout<<"\nEncrypting Key ..."; KeyEnc(e,n); cout<<"\nDecrypting Key..."; KeyDec(d,n); cout<<"\nFinish [key.txt]"; getch(); } void KeyEnc(int e,int n) { ifstream fin("d:\\key.txt"); ofstream fout("d:\\keyEnc.txt"); char str[10]; ul i,X,Y,j; for(j=0;j<8;j++) { for(i=0;i<8&&!fin.eof();i++) { fin.get(str[i]); } str[8]='\0'; // cout<<str<<","; X=Bin2Num(str); Y=Crypt(X,e,n); // cout<<X<<","<<Y<<endl; fout<<Y<<endl; getch(); } fin.close(); fout.close(); } void KeyDec(int d,int n) { ifstream fin("d:\\keyEnc.txt"); ofstream fout("d:\\keyDec.txt"); char ch; ul i,X,Y; char *str=new char[20]; int Ch; while(!fin.eof()) { fin>>Ch; if(fin.eof()) return; cout<<Ch; Y=Crypt(Ch,d,n); // cout<<","<<Y; str=Num2Bin(Y); // cout<<","<<str<<endl; fout<<str; getch(); } fin.close(); fout.close(); } |
|
|
|
[讨论]为什么这儿没人发帖
好吧~~ 偷偷告訴你一個秘密~~ 實際上 XSS 對 vBulletin 3.8.4 版本有效,所以它也對 vBulletin 3.8.3 版的有效~ 多閱讀有關 VB XSS 的文章,你將會知道如何運用你的 FireFox 的 Plugin 來偷取 User 的 cookie, 來達到登入論壇的目的。 |
|
[转帖]當女友變成妻子
沒啊~~你的親密戰友說的~ |
|
[转帖]當女友變成妻子
你不是正在申請移民嗎? 進度如何~ |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值