Bài tập thực hành phần mật mã

Tài liệu Bài tập thực hành phần mật mã: BÀI TẬP THỰC HÀNH PHẦN MẬT MÃ (12 tiêt) Bài 1 : Kiểm tra số nguyên tố : #include #include void main() { clrscr(); int x , n; cout<<"nhap vao so nguyen can kiem tra: ";cin>>x; n=2; while(x%n>0) { n++; } if (n==x ) cout<<"La so nguyen to"; else cout<<"Khongla so NT"; getch(); } Bài 2 :Tạo N số nguyên tố đầu tiên #include #include #define N 100 int i,j,k; long int q,r,n,pr[N+1]; int main() { pr[1]=2;n=3;j=1; label1:j++;pr[j]=n; if (j==N) goto label4; label2: n+=2;k=2; label3: q=n/pr[k];r=n%pr[k]; if(r==0) goto label2; if (q<=pr[k]) goto label1; k++;goto label3 ; label4: for(i=1;i<=N;i++) { printf("%1d ",pr[i]); if(i%10==0) printf(" "); } getchar(); return(n,j,k); }/*main*/ Bài 3 Biểu diễn theo cơ số B /*BIEU DIEN CO SO B*/ #include #include /* input : two non_negative intergers a,b ,b>=2 output : base b representation of a */ int a,b...

pdf73 trang | Chia sẻ: Khủng Long | Lượt xem: 1038 | Lượt tải: 0download
Bạn đang xem trước 20 trang mẫu tài liệu Bài tập thực hành phần mật mã, để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên
BÀI TẬP THỰC HÀNH PHẦN MẬT MÃ (12 tiêt) Bài 1 : Kiểm tra số nguyên tố : #include #include void main() { clrscr(); int x , n; cout<<"nhap vao so nguyen can kiem tra: ";cin>>x; n=2; while(x%n>0) { n++; } if (n==x ) cout<<"La so nguyen to"; else cout<<"Khongla so NT"; getch(); } Bài 2 :Tạo N số nguyên tố đầu tiên #include #include #define N 100 int i,j,k; long int q,r,n,pr[N+1]; int main() { pr[1]=2;n=3;j=1; label1:j++;pr[j]=n; if (j==N) goto label4; label2: n+=2;k=2; label3: q=n/pr[k];r=n%pr[k]; if(r==0) goto label2; if (q<=pr[k]) goto label1; k++;goto label3 ; label4: for(i=1;i<=N;i++) { printf("%1d ",pr[i]); if(i%10==0) printf(" "); } getchar(); return(n,j,k); }/*main*/ Bài 3 Biểu diễn theo cơ số B /*BIEU DIEN CO SO B*/ #include #include /* input : two non_negative intergers a,b ,b>=2 output : base b representation of a */ int a,b; long repre(int a,int b); long repre0(int a,int b); void main() { a=12;b=2; repre(a,b); a=8;b=4; repre(a,b); a=15245;b=32; repre(a,b); a=748;b=16; repre(a,b); a=14;b=2; repre0(a,b); getchar(); }/* main */ long repre(int a,int b) { int n,i,A[20];long x,q; n=0;q=a/b;A[n]=a%b; while(q>0) { n++;x=q;q=x/b;A[n]=x%b; }/* end while */ printf("a=%1d b=%1d n=%1d\n " ,a,b,n); for(i=0;i<=n;i++) printf(" A[%d]=%1d\n ",i,A[i]); } /* b-representation */ long repre0(int a,int b) { int A0,A1; A0=a%b;A1=(a/b)%b; printf("a=%ld d=%1d A0=%1d A1=%1d ",a,b,A0,A1); }/* b-representation */ Bài 4 : Cộng hai số biểu diễn theo cơ số B #include #include /* input : Two positive integers x,y in base b representation output : x+y in base b representation */ long a,b,x,y,z,t; int A[100],X[100],Y[100],Z[100],i,n,N; long repre(long a,long b); long add(long x,long y); void main() { x=2748;y=659260;b=32; a=x; /*printf("a=%d b=%d x=%d y=%d \n",a,b,x,y);*/ repre(a,b); N=n; for(i=0;i<=n;i++) X[i]=A[i]; a=y;repre(a,b);if(N<n) N=n; for(i=0;i<=n;i++) Y[i]=A[i]; printf("x=%ld y=%ld b=%ld N=%d \n",x,y,b,N); for(i=0;i<=N;i++) printf("X[%d]=%d Y[%d]=%d \n",i,X[i],i,Y[i]); add(x,y); for(i=0;i<=N;i++) printf("Z[%d]=%d \n",i,Z[i]); /* verification */ z=Z[0];t=1; for(i=1;i<=N+1;i++) {t*=b;z+=(Z[i]*t);} printf("z=%ld x+y=%ld \n",z,x+y);getchar(); }/* main */ long repre(long a,long b) { long q,qq ; n=0 ; q =a/b ; A[n]=a%b ; while(q>0) {n++ ; qq=q ; q=qq/b ; A[n]=qq%b;} } /* b - representation */ long add(long x,long y) { int ii,c=0,tem; /* c is the carry digit */ for(ii=0;ii<=n;ii++) { tem=(X[ii]+Y[ii]+c); if(tem<b) {Z[ii]=tem;c=0;} else {Z[ii]=tem-b;c=1;} }/* ii */ Z[N+1]=c; }/* add */ Bài 5 Nhân hai số theo cơ số B # include # include /* input : 2 positive integers x , y in base b representation, b>=2 , having N+1 digits respectively ; output : x*y in base b representation , with N+M+2 digits */ long a,x,y,z,t,bb,b,k,B[20] ; int A[20],X[20],Y[20],Z[20],i,n,N,M,A0,A1; long repres(long x,long b); long mult(long x,long y); void main () /* cr5i. C , 21 / 6 / 1998 */ { x=659260 ; y=2748 ; b=32 ; repres(x,b) ; N=n ; for(i=0 ; i<=n ; i++ ) X[i]=A[i] ; repres(y,b) ; N=n ; for(i=0 ; i<=n ; i++) Y[i]=A[i] ; printf("x=%ld y=%ld b=%ld N=%ld M=%ld ",x,y,b,N,M); for (i=0 ; i<=N ;i++) printf("X[%d]=%d Y[%d]=%d",i,X[i],i,Y[i]); mult (x,y) ; for (i=0 ; i<=N+M+1 ; i++) printf("Z[%d]=%d ",i,Z[i]); /* verification */ z=Z[0] ; t=1 ; for(i=0 ; i<=(N+M+1) ; i++) {t*=b ; z+=(Z[i]*t) ;} printf ( "z=%ld x*y=%ld" ,z,x*y ) ; } /*MAIN*/ long mult (long x,long y) { int ii,jj,ca ; for(ii=0 ; ii<= N+M+1 ; ii++ ) Z[ii]=0 ; for (ii=0 ; ii<=M ; ii++) { ca=0 ; for(jj=0 ; jj<=N ; jj++ ) { a=Z[ii+jj]+(X[jj]*Y[ii])+ca ; k=1 ; while(k*b<=a) k++ ; k-- ; A1=k ; A0=a-k*b; Z[ii+jj]=A0 ; ca=A1; } /* jj */ Z[ii+N+1]=A1; } /* ii */ } /* mult */ long a0; int b0 ; long repes (long a0 ,int b0 ) { n=0 ; bb=1 ; B[0]=1 ; while(bb<a0) {bb*=b0 ; n++ ; B[n]=bb ; } n-- ; for (i=n ; i>0 ; i--) { bb=B[i] ; k=1 ; while(( k*bb) <= a0) k++ ; k--; A[i]=k ; a0-=k*bb ; } A[0]=a0; } /* b - repres*/ Bài 5: Thuật giải Beazout tính gcd của a & b /*Bezout*/ #include #include long A,B; long bezout(long A,long B); void main() /*main*/ { A=9; B=0; bezout(A,B); A=13; B=17;bezout(A,B); A=21; B=36; bezout(A,B); A=2145378312; B=1256993; bezout(A,B); getchar(); } /*Main*/ long a,b; long bezout(long a,long b) { long d,q,r,x,x1,x2,y,y1,y2,tem; if (b==0) { d=a;x=1;y=0; } else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b;r=a-q*b;x=x2-q*x1;y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; } d=a;x=x2;y=y2; } tem=A*x+B*y-d; /* if (y<0) y=A+y;*/ printf("A=%ld B=%ld d=%ld x=%ld y=%ld tem=%ld ",A,B,d,x,y,tem); return(a,b); }/*bezout*/ Bài 6 : Tính lũy thừa modulo nghich đảo /* Multiplicative inverse (ok!) */ #include #include long A,B; long inverse(long B, long A); void main() { B=28; A=25; inverse(B,A); B=13; A=3; inverse(B,A); B=12; A=5; inverse(B,A); B=13; A=3; inverse(B,A); getchar(); } long a,b; long inverse(long b,long a) { long d,q,r,x,x1,x2,y,y1,y2,tem; if (b==0) { d=a;x=1;y=0; } else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b;r=a-q*b;x=x2-q*x1;y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; } d=a;x=x2;y=y2; } tem=A*x+B*y-d; if (y<0) y=A+y; printf("A=%ld B=%ld d=%ld x=%ld y=%ld tem=%ld \n ",A,B,d,x,y,tem); } Bài 7 : Chương trình mã –dich dùng RSA /* Chuong trinh MA-DICH tren RSA . Plain text duoc bieu dien duoi dang mot day so nguyen */ #include #include #include #define I 4 #include long Q[40]; int n,N,M; typedef long vector[I+1]; long MP(long long x,long y,long z); long inverse(long x,long m),ME(long x,long y,long z); long BR(long s); void main() {/*main*/ clrscr(); long q1,p1,M1,x1,phi1,e1,d1,xx,xx1,xx2,xx3, p2,q2,M2,phi2,e2,d2,yy,yy1,yy2,yy3,now0,now,user_time; now0=time(NULL); p1=2699;q1=795659; M1=p1*q1; printf("p1=%ld q1=%ld M1=%ld ",p1,q1,M1); phi1=(p1-1)*(q1-1);e1=3674911; d1=inverse(e1,phi1); printf("phi1=%ld e1=%ld d1=%ld \n",phi1,e1,d1);printf(""); p2=5843;q2=367531;M2=p2*q2;phi2=(p2-1)*(q2-1); e2=3674911;printf("p2=%ld q2=%ld M2=%ld ",p2,q2,M2); d2=inverse(e2,phi2); printf("phi2=%ld e2=%ld d2=%ld \n",phi2,e2,d2);printf(""); xx=12345; xx1=ME(xx,M1,e1);xx2=ME(xx1,M1,e1);xx3=ME(xx2,M1,e1); yy1=ME(xx3,M2,e2);yy2=ME(yy1,M2,e2);yy3=ME(yy2,M2,e2) ; cprintf("\n KET QUA MA : ",yy3); printf("xx=%ld \n\nxx1=%ld xx2=%ld xx3=%ld \n",xx,xx1,xx2,xx3); printf("yy1=%ld yy2=%ld yy3=%ld \n",yy1,yy2,yy3); yy2=ME(yy3,M2,d2);yy1=ME(yy2,M2,d2);xx3=ME(yy1,M2,d2) ; xx2=ME(xx3,M1,d1);xx1=ME(xx2,M1,d1);xx=ME(xx1,M1,d1); /* m=c^d modNN=RO */ cprintf("\n KET QUA DICH : ",xx); printf("xx=%ld \n\nxx1=%ld xx2=%ld xx3=%ld \n",xx,xx1,xx2,xx3); printf("yy1=%ld yy2=%ld yy3=%ld \n",yy1,yy2,yy3); now=time(NULL);user_time=now-now0; printf("\nuser_time = %d seconds ",user_time,"seconds");getchar(); }/*main*/ long x0,m0,p0; long ME(long x0,long m0,long p0) { long A0,p1,Z[40];int i1; BR(p0);N=n;for (i1=0;i1<=N;i1++) Z[i1]=Q[i1]; /*for (i1=0;i1<=N;i1++) printf("Q[%d]=%ld \n",i1,Q[i1]);getchar();*/ A0=x0%m0;p1=1;/* A0=x1modMM B pesentation of x1*/ if(p0>0); { if (Z[0]>0) p1=A0; for(i1=1;i1<=N;i1++) { A0=MP(A0,A0,m0); if(Z[i1]>0) p1=MP(A0,p1,m0); }/*i1*/ } return (p1); }/*phep tinh luy thua modulo*/ long s; long BR(long s) { int ii; long x,q; ii=0;x=s;q=(x>>1);Q[ii]=x-(q<<1); while (q>0) { ii++;x=q;q=(x>>1);Q[ii]=x-(q<<1); } n=ii; }/*Bit-Representation,bieu dien x theo bimary*/ long x,y,k; long MP(long x,long y,long k) { int ii;long P,t1,t2,Y[40];double tem;t1=x;t2=y; if(x<0) {x=-x;x=k-(x%k);} else x=x%k; if(y<0) {y=-y;y=k-(y%k);} else y=y%k; if ((x==0)||(y==0)) {P=0;goto label1;} BR(y); M=n; for(ii=0;ii<=M;ii++) Y[ii]=Q[ii]; if(Y[0]>0) P=x; else P=0; for(ii=1;ii<=M;ii++) { tem=2.0*x; if(tem>=k) tem-=k; x=(long)tem; if(Y[ii]>0) { tem+=P; if(tem>=k) P=(long)(tem-k); else P=(long)tem; } }/*ii*/ x=t1; y=t2; label1:return(P); }/*phep nhan modulo*/ long b,a;/*0<b<a,Multicative inverce of b mod a*/ long inverse(long b,long a) { long A,B,d,q,r,x,x1,x2,y,y1,y2,tem; A=a;B=b; /*Dung Beazout*/ if(b==0) { d=a;x=1;y=0; }/*if*/ else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b; r=a-q*b; x=x2-q*x1; y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; }/*while*/ d=a;x=x2;y=y2; }/*else*/ tem=A*x+B*y-d; if(y<0) y=A+y; return(y); }/*inverse*/ Bài 8 : RSA mã chuỗi ký tự : plain text được nhập vào dưới dạng một chuỗi ký tự #include #include #include #include #include #include #include long MP(long long ,long ,long ); //Nhan luy thua long inverse(long ,long ); //Modulo nghich dao long ME(long ,long ,long ); //Luy thua modulo void BR(long ); //Doi sang dang bit (co so 2) int SNT(long); int snt( long); long Bezout (long a, long b);//tinh gcd long Q[40]; int n,N,M; long MP(long long x,long y,long k){ //Nhan luy thua int ii; long P,t1,t2,Y[40]; double tem; t1=x; t2=y; if(x<0){ x = -x; x = k - (x%k); } else x = x%k; if(y<0){ y = -y; y = k - (y%k); } else y = y%k; if(x==0 || y==0){ P=0; return P; } BR(y); M=n; for(ii=0;ii<=M;ii++) Y[ii]=Q[ii]; if(Y[0]>0) P = x; else P = 0; for(ii=1;ii<=M;ii++){ tem=2.0*x; if(tem>=k) tem -= k; x = (long)tem; if(Y[ii] > 0){ tem +=P; if(tem>=k) P = (long)(tem-k); else P = (long)tem; } } x = t1; y = t2; return P; } long inverse(long b,long a){ //Modulo nghich dao long A,q,r,x,x1,x2,y,y1,y2; A = a; if(b == 0){ x = 1; y = 0; } else{ x2 = 1; x1 = 0; y2 = 0; y1 = 1; while(b>0){ q = a/b; r = a - q*b; x = x2 - q*x1; y = y2 - q*y1; a = b;b = r;x2 = x1; x1 = x; y2 = y1; y1 = y; } x = x2; y = y2; } if(y<0) y = A + y; return y; } long ME(long x0,long m0,long p0){ //Tính Luy thua Modulo long A0,p1,Z[40]; int i1; BR(p0); N=n; for(i1=0;i1<=N;i1++) Z[i1] = Q[i1]; A0 = x0%m0; p1 = 1; if(p0>0);{ if(Z[0]>0) p1=A0; for(i1=1;i1<=N;i1++){ A0=MP(A0,A0,m0); if(Z[i1]>0) p1=MP(A0,p1,m0); } } return p1; } void BR(long s){ //Doi sang dang bit (co so 2) int ii; long x,q; ii = 0; x = s; q = (x>>1); Q[ii] = x - (q<<1); while(q>0){ ii++; x = q; q = (x>>1); Q[ii] = x - (q<<1); } n = ii; } int SNT(long n){ if(n == 1 || n == 2) return 1; int i=3;while(n%i!=0)i++;i--; if(n == i) return -1; return 1; } void main(){ clrscr(); long q1,p1,M1,phi1,e1,d1,xx[25]={0},xx1[25]={0},xx2[25]={0},xx3 [25]={0}; //tao ngau nhien SNT randomize(); long arr[30]={0},z,y,x; cout<<"\n Day so nguyen to(Ban co the chon!):"; int i=0; for( int j=0;j<50;j++) { if((z=snt(random(10000)))!=0) { arr[i]=z;i++; } } for( j=0;j<i;j++) cout<<setw(10)<<arr[j]; cout<<"\nNHAP CAP SO NGUYEN TO THU NHAT:"; do{ cout<<"\nNhap so nguyen to thu nhat p1 = "; cin>>p1; }while(SNT(p1)<0); do{ cout<<"\nNhap so nguyen to thu hai q1 = "; cin>>q1; }while(SNT(q1)<0); M1 = p1*q1; cout<<"p1 = "<<p1<<" q1 = "<<q1<<" M1 = "<<M1<<endl; phi1 = (p1-1)*(q1-1); do{ cout>e1; }while(Bezout(e1,phi1)!=1); d1=inverse(e1,phi1); cout<<" phi1 = "<<phi1<<" e1 = "<<e1<<" d1 = "<<d1; char a[25]; cout<<"\nNHAP VAN BAN CAN MA HOA: "; gets(a); int n= strlen(a); cout<<"chieu dai chuoi = "<<n<<endl; cout<<"\nVAN BAN CAN MA HOA "<<a; for(int ii=0;ii<n;ii++) { if((a[ii]!=' ')) { xx[ii]= (a[ii] - '0'); } else xx[ii]=a[ii]; } cout<<"\n chuoi sau khi doi thanh so: "<<xx; for( ii=0;ii<n;ii++) xx1[ii]=ME(xx[ii],M1,e1); for( ii=0;ii<n;ii++) xx2[ii]=ME(xx1[ii],M1,e1); for( ii=0;ii<n;ii++) xx3[ii]=ME(xx2[ii],M1,e1); cout<<"\nKET QUA MA (van ban ma):"<<xx3<<endl; getch(); //giai ma for( ii=0;ii<n;ii++) xx2[ii]=ME(xx3[ii],M1,d1); for( ii=0;ii<n;ii++) xx1[ii]=ME(xx2[ii],M1,d1); for( ii=0;ii<n;ii++) xx[ii]=ME(xx1[ii],M1,d1); // cout<<"\n Sau giai ma (chua doi thanh ky tu):"<<xx; for(ii=0;ii<n;ii++) { if(xx[ii]!=32) a[ii]= char(xx[ii] + '0'); else a[ii]=' '; } cout<<"\nKET QUA DICH (BANG RO): "<<a; getch(); } long Bezout (long a, long b) { long d,q,r,x,x1,x2,y,y1,y2; if (b==0) { d=a; x=1; y=0; } else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b;r=a-q*b;x=x2-q*x1;y=y2-q*y1; a=b; b=r; x2=x1;x1=x;y2=y1; y1=y; } d=a; x=x2;y=y2; } return d; } int snt(long n) { for(int i=2;i<n;i++) { if((n%i)==0) { n=0; break; } } return n; } Bài 9: Mã hĩa một file text (thu1.txt) dùng RSA /* Mã một file text dùng RSA */ #include #include #include #define I 4 #include long Q[40]; FILE *fp1; int n,N,M; long q1,p1,M1,x1,phi1,e1,d1,xx,xx1,xx2,xx3, p2,q2,M2,phi2,e2,d2,yy,yy1,yy2,yy3; typedef long vector[I+1]; long MP(long long x,long y,long z); long inverse(long x,long m),ME(long x,long y,long z); long BR(long s);/*long codage(long x,long y,long z,long t,long v);*/ void main() {/*main*/ long now0,now,user_time,i2=0; clrscr(); now0=time(NULL); p1=2699;q1=795659; M1=p1*q1; printf("p1=%ld q1=%ld M1=%ld ",p1,q1,M1); phi1=(p1-1)*(q1-1);e1=3674911; d1=inverse(e1,phi1); printf("phi1=%ld e1=%ld d1=%ld \n",phi1,e1,d1);printf(""); p2=5843;q2=367531;M2=p2*q2;phi2=(p2-1)*(q2-1); e2=3674911; printf("p2=%ld q2=%ld M2=%ld ",p2,q2,M2); d2=inverse(e2,phi2); printf("phi2=%ld e2=%ld d2=%ld \n",phi2,e2,d2);printf(""); fp1=fopen("a:\thu1.txt","rb"); printf("KET QUA MA : \n"); while(fread(&xx,sizeof(xx),1,fp1)==1) { /*codage(xx,M1,e1,M2,e2);*/ xx1=ME(xx,M1,e1); xx2=ME(xx1,M1,e1);xx3=ME(xx2,M1,e1); yy1=ME(xx3,M2,e2); yy2=ME(yy1,M2,e2);yy3=ME(yy2,M2,e2); i2++;printf("%lx ",yy3); if(i2%7==0)printf(""); } fclose(fp1); now=time(NULL);user_time=now-now0; printf("\n user_time = %d seconds ",user_time,"seconds");getchar(); }/*main*/ long x0,m0,p0; long ME(long x0,long m0,long p0) { long A0,p1,Z[40];int i1; BR(p0);N=n;for (i1=0;i1<=N;i1++) Z[i1]=Q[i1]; /*for (i1=0;i1<=N;i1++) printf("Q[%d]=%ld \n",i1,Q[i1]);getchar();*/ A0=x0%m0;p1=1;/*printf ("A0=%ld N=%d ",A0,N);getchar();/* A0=x1modMM B pesentation of x1*/ if(p0>0); { if (Z[0]>0) p1=A0; for(i1=1;i1<=N;i1++) { A0=MP(A0,A0,m0); if(Z[i1]>0) p1=MP(A0,p1,m0); /*printf("i1=%d A0=%ld p1=%ld \n",i1,A0,p1);*/ }/*i1*/ }/* printf("p1=%ld ",p1); getchar();*/ return (p1); }/*phep tinh luy thua modulo*/ long s; long BR(long s) { int ii; long x,q; ii=0;x=s;q=(x>>1);Q[ii]=x-(q<<1); while (q>0) { ii++;x=q;q=(x>>1);Q[ii]=x-(q<<1); } n=ii; }/*Bit-Representation,bieu dien bit*/ long x,y,k; long MP(long x,long y,long k) { int ii; long P,t1,t2,Y[40]; double tem; t1=x; t2=y; if(x<0) {x=-x;x=k-(x%k); } else x=x%k; if(y<0) {y=-y;y=k-(y%k); } else y=y%k; if ((x==0)||(y==0)) { P=0; goto label1; } BR(y); M=n; for(ii=0;ii<=M;ii++) Y[ii]=Q[ii]; if(Y[0]>0) P=x; else P=0; for(ii=1;ii<=M;ii++) { tem=2.0*x; if(tem>=k) tem-=k; x=(long)tem; if(Y[ii]>0) { tem+=P; if(tem>=k) P=(long)(tem-k); else P=(long)tem; } }/*ii*/ x=t1; y=t2; label1: return(P); }/*phep nhan modulo*/ long b,a;/*0<b<a,Multicative inverse of b mod a*/ long inverse(long b,long a) { long A,B,d,q,r,x,x1,x2,y,y1,y2,tem; A=a;B=b; if(b==0) { d=a;x=1;y=0; }/*if*/ else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b; r=a-q*b; x=x2-q*x1; y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; }/*while*/ d=a;x=x2;y=y2; }/*else*/ tem=A*x+B*y-d; if(y<0) y=A+y; return(y); }/*inverse*/ /* long codage(long x, long y ,long z,long t,long v) { }/*codage*/ BÀI 10 :Bài tổng hợp :CHƯƠNG TRÌNH HỆ THỐNG BẢO MẬT – XÁC THỰC DÙNG RSA Tạo menu chương trình Bấm (K) –tạo khĩa : Menu tạo khĩa : 1.Tạo bảng SNT ( hoặc đưa SNT từ BF song phải kiểm tra số NT) 2. Chọn p&q trong bảng 3. Tạo khĩa : Chương trình tự động tính N=p*q Chương trình tính Fi = (p-1)*(q-1) Chọn cơng việc: a. Tạo khĩa (K) b. Xác thực (A) c. Bảo mật (C) d. Thốt ra ngồi HT (X) Yêu cầu chọn e (nhập e từ KB) Chương trình K/tra e cĩ NTCN với Fi Nếu e khơng là số NT cùng nhau với Finhập lại e Chương trình tính tiếp d = èmod N (Dùng Beazout) Xuất cặp khĩa (e,N) và (d,N) Ví dụ p=3,q=5;p*q=15 ; Fi=(p-1)*(q-1)=8 Chọn e = 3 d =3-1mod8 = 3 Xuất (3,15) và (3,15) Thốt về main menu Bấm A ( Authenticate) 1.Yêu cầu nhập văn bản gốc cần xác thực - Nhập từ KB số nguyên m Trong thực tế : Nhập text  chuyển khối dữ liệu thành số nguyên - Nhập khĩa từ bảng khĩa (d,N) (của tơi) - Mã xác thực : c = md mod N  gửi đi - Bên nhận (cần xác thực) dùng Public Key của “tơi” để giải .--> giả được “tơi” đúng là tơi. Bấm C ( bảo mật thơng điệp). Nhập thơng điệp cần bảo mật “m” từ KB Lấy (e,N) của bên nhận thơng điệp từ bang khĩa hoặc PK server Mã bằng (e,N) của bên nhận : c= me modN gửi c đi. Bên nhận dùng (d,N) của mình để giải mật. Nếu giải được  OK! Thốt ra menu chính Hỏi cĩ tiếp tục Ko??? Yes ! Trở về menu chính No ! Bye bye! Thốt ra HĐH BÀI TẬP THỰC HÀNH AN TỒN & BẢO MẬT THƠNG TIN PHẦN 2 : AN TỒN VÀ BẢO MẬT HỆ THỐNG (12 tiết) Bài 1 : Sao lưu dự phịng dữ liệu  B 1: Khởi động máy vào log on Admin , vào thư mục C: tạo thư mục (Dulieu) và các file h1.txt , h2.txt ; sau đĩ vào D: tạo thư mục Backup  B2: Start → Programs →Accessories → Systems Tools → Backup →tại cửa sổ Welcome →bỏ dấu chọn ơ Always start in wizard mode → Click chọn Advance Mode → tại cửa sổ Backup Utility chọn tab Backup → click vào dấu “+” tại C: và đánh dấu chọn vào ơ Dulieu → tại cửa sổ Backup media or file name chọn tab Browse → chỉ đường dẫn tới D:\Backup và lưu file backup với tên (bk1.bkf). Sau đĩ chọn Start Backup →tại cửa sổ Backup Job Information chọn Start Backup. Sau khi Backup Progress xong → Vào D:\Backup để kiểm tra xem cĩ file “bk1.bkf” chưa ?  B3 : vào C:\Dulieu , click nút phải chuột trên h1.txt → Properities → tab General → chọn Advance →bỏ dấu chọn File is ready for archiving  B4 : Mở file h1.txt nhập thêm vào nội dung và lưu lại →click chuột phải trên h1.txt → Properities → tab General → chọn Advanced → bỏ dấu chọn File is ready for archiving  B5 : Mở chương trình Backup, tại cửa sổ Backup Utility chọn tab Backup →Click dấu ‘+’ tại C: và đánh dấu chọn vào ơ dữ liệu →tại mục Backup media or file name gõ “D:\Backup\dif.bkf” →chọn Start Backup →tại cửa sổ Backup Job Information chọn Advance →tại cửa sổ Advanced Backup Options , tại mục Backup Type chọn Differential → OK →Start Backup  B6 : tại cửa sổ Backup Utility chọn tab Restore and Manage Media và click dấu ‘+’ tại mục dif.bkf →Click dấu ‘+’ tại C: và chọn Dulieu (chỉ cĩ h1.txt được backup). Sau đĩ đĩng các cửa sổ , kế tiếp vào thư mục C:\Dulieu → Click chuột phải trên h1.txt →Properities →tab General → Advanced (đánh dấu chọn mục File is ready for archiving  B7 : Mở file h2.txt nhập thêm nội dung và save lại →Click chuột phải trên h2.txt → Properities →tab General → Advanced (đánh dấu chọn mục File is ready for archiving  B8: Mở chương trình Backup →chọn tab Backup , sau đĩ click dấu ‘+’ tại C: , đánh dấu chọn vào ơ Dulieu, tại mục Backup media or file name gõ D:\Backup\inc.bkf , sau đĩ chọn Start Backup  B9: tại cửa sổ Backup Job Information chọn Advanced → tại cửa sổ Advanced Backup Options , click vào mục Backup Type và chọn Incremental →OK →Start Backup.  B10: tại cửa sổ Backup Utility chọn tab Restore and Manage Media , click dấu ‘+’ tại mục inc.bkf, kế tiếp click dấu ‘+’ tại mục C:\Dulieu BÀI 2 : RESTORE DATA  B1 : Xĩa thư mục Dulieu  B2: Mở chương trình Backup →chọn Menu Tools →Options →tab Restore → đánh dấu chọn vào mục Replace the file on disk only if the file on disk is older  B3: tại cửa sổ Backup Utility →vào tab Restore and Manage Media → click vao file →bk1.bkf → C: và đánh dấu chọn vào Dulieu → Chọn Start Restore → tại cửa sổ confirm restore chọn OK. BÀI 3 : Ẩn Control Panel  B1 : Vào Start → Run →MMC → OK  B2 : Sẽ xuất hiện màn hình Console1, chọn File →Add/Remove Snap-in →Add →tại cửa sổ Add Standalone Snap-in →Group Policy Object Editor →Add →Finish.  B3 : Tại màn hình Console1, chọn File →Save as (tại cửa sổ save in chọn Destop và File name : Local Policy)  B4 : Vào Local Policy →Local Computer Policy → User Configuration → Administrator Templates →Control Panel  B5 : Vào Prohibit access to the Control Panel →Properties (đánh dấu chọn Enable , sau đĩ apply và OK)  B6 : Vào Start → Run →cmd →gpupdate /force BÀI 4 : Ghi nhận quá trình đăng nhập (Logon)  B1 : Start →Programs →Administrative Tools →Local Security Policy →Local Policies → Audit Policy → Click chuột phải lên Audit Account Logon Events → Properties → đánh dấu chọn Failure → Apply → OK →cập nhật policy (gpupdate \force)  B2 : Start →Programs →Administrative Tools →Event viewer → click chuột phải lên Security → chọn Clear all events → chọn No. BÀI 5 : NETWORK MONITORING Chọn 2 máy tính : máy tính 1 cĩ địa chỉ IP :192.168.1.1 và máy tính 2 cĩ địa chỉ IP : 192.168.1.2.  B1: Start → Settings →Control Panel → Add/Remove Programs → Add/Remove Windows Component →chọn mục Management and Monitoring Tools →Details →đánh dấu chọn vào ơ Network MonitorTools →OK → Next.  B2 : Start →Administrative Tools →Network Monitor →tại cửa sổ Microsoft Network Monitor, chọn OK →tại cửa sổ Select a network, click dấu ‘+’ ở mục Local Computer → chọn card LAN → OK  B3 : Tại cửa sổ Network Monitor → chọn Capture →Start. (Chú ý để nguyên màn hình Network Monitor)  B4 : Start →Run →gõ cmd →ta dùng lệnh ping địa chỉ IP giữa 2 máy tính : ping 192.168.1.1 và ping 192.168.1.2.  B5 : Quay lại màn hình Network Monitor → chọn Capture →Stop and View → double click trên dịng cĩ protocol là ICMP BÀI 6 : IP SECURITY (IP SEC) Chọn 2 máy tính : máy tính 1 cĩ địa chỉ IP : 192.168.1.1 và máy tính 2 cĩ địa chỉ IP : 192.168.1.2.  B1 : Start →Run →gõ MMC →tại cửa sổ Consol →chọn Menu File → Add/Remove Snap-in →tại cửa sổ Add/Remove Snap-in , tại mục Snap in add to : Consol Root, sau đĩ chọn Add →Kéo thanh trượt chọn mục IP Security Policy Management →chọn Add → tại cửa sổ Select Computer or Domain , chọn ơ Local Computer →Finish →Close →OK  B2 : Tại cửa sổ Consol1 →click chuột phải trên IP Security Policies on Local Computer →chọn Create IP Security Policy→tại cửa sổ Welcome chọn Next → tại cửa sổ IP Security Policy Name gõ ‘IPSec bang Preshare Key’ vào ơ name →Next → tại cửa sổ Request for Secure Communication, bỏ dấu chọn tại mục Activate the default → Next → Finish →tại cửa sổ Test IP Sec Preshare Key Properties → chọn Add →tại cửa sổ Welcome → Next → tại cửa sổ Tunnel Endpoint chọn This rule does not specify a tunnel → Next → tại cửa sổ Network Type , chọn ơ Local area network LAN →Next→tại cửa sổ IP Filter List, chọn mục All IP →Next →tại cửa sổ Filter Action , chọn mục Require Security → Next →trong cửa sổ Authentication Method, chọn mục Use this string to protect the key exchange, trong hộp thoại gõ ‘123’ →Next →Finish.  B3 : Tại cửa sổ Consol1, click chuột phải lên IPSec bang Preshare Key → Assign →lưu Consol1 ra màn hình Desktop →đĩng các cửa sổ đang cĩ và cập nhật Policy(gpupdate /force)  B4 : Start →Progarms →Administrative Tools →Services →click chuột phải lên IPSEC Service, chọn Restart.  B5: Mở chương trình Network Monitor →chọn Capture →Start  B6 : Start →Run →cmd →ta dùng lệnh ping địa chỉ IP giữa 2 máy tính : ping 192.168.1.1 và ping 192.168.1.2  B7 : Quay lại màn hình Network Monitor→ chọn Capture → chọn Stop and View → double click trên dịng cĩ Protocol là ESP →chọn mục ESP. Bài 7 : Quản lý local Password Như chúng ta đã học ở phần lý thuyết, Module System Hacking bao gồm những kỹ thuật lấy Username và Password, nâng quyền trong hệ thống, sử dụng keyloger để lấy thơng tin của đối phương(trong bước này cũng cĩ thể Hacker để lại Trojan, vấn đề học ở chương tiếp theo), ẩn thơng tin của process đang hoạt động(Rootkit), và xĩa những log hệ thống. Trong bài tập này ta sử dụng phầm mềm Cain để kiểm tra password của user. Bước 1 Ta cài phần mềm CAIN vào máy đối phương Tạo một user longdao từ cmd : C:\Documents and settings\longdt>user net longdao 12345 /add Bước 2 : Bật phầm mềm Cain và chọn Import Hashes from local system Ở đây chúng ta thấy cĩ 3 chế độ, “ Import hash from local system”, ta sử dụng file SAM của hệ thống hiện tại để lấy hash của account(khơng cĩ mã hĩa syskey), Option Import Hashes from text file, thơng thường text file này là lấy từ Pwdump(lưu hash của account hệ thống dưới dạng khơng bị mã hĩa), Option thứ 3 là khi chúng ta cĩ syskey và file SAM bị mã hĩa bởi syskey. Ca ba trường hợp nếu nhập đầy đủ thơng tin chúng ta đều cĩ thể cĩ hash của account khơng bị mã hĩa bởi syskey. Dựa vào thơng tin hash này phần mềm sẽ brute force để tìm kiếm password của account. Bước 3 : Chọn user cần crack mật khẩu Bước 4 : crack mật khẩu dùng Brute force NTLM hash Trong bài ta chọn user longdao, kích phải tên user vừa chon và chọn Brute force theo NTLM hash.Chọ start. Sau khi chọn chế độ này ta thấy PC bắt đầu tính tốn và cho ra kết quả. Kết quả : password of longdao user is 12345 BÀI THỰC HÀNH SYSTEM HACKING BÀI 1: FOOTPRINTING Đây là kỹ thuật giúp hacker tìm kiếm thơng tin về 1 doanh nghiệp, cá nhân hay tổ chức. Bạn cĩ thể điều tra được rất nhiều thơng tin của mục tiêu nhờ vào kỹ thuật này. Ví dụ trong phần thực hành thứ 1 chúng ta áp dụng kỹ thuật này tìm kiếm thơng tin về một domain(ví dụ là www.itvietnam.com) và xem thử email liên lạc của domain này là của ai, trong phần thực hành thứ 2 chúng ta truy tìm 1 danh sách các email của 1 keywork cho trước, phương pháp này hiệu quả cho các doanh nghiệp muốn sử dụng marketing thơng qua hình thức email v.v. Trong giai doạn này Hacker cố gắng tìm càng nhiều thơng tin về doanh nghiệp(thơng qua các kênh internet và phone) và cá nhân(thơng qua email và hoạt động của cá nhân đĩ trên Internet), nếu thực hiện tốt bước này Hacker cĩ thể xác định được nên tấn cơng vào điểm yếu nào của chúng ta. Ví dụ muốn tấn cơng domain www.itvietnam.com thì Hacker phải biết được địa chỉ email nào là chủ cùa domain này và tìm cách lấy password của email thơng qua tấn cơng mail Server hay sniffer trong mạng nội bộ v.v. Và cuối cùng lấy được Domain này thơng qua email chủ này. Bước 1: Tìm thơng tin về Domain Ta vào trang www.whois.net để tìm kiếm thơng tin và đánh vào domain mình muốn tìm kiếm thơng tin Sau đĩ ta nhận được thơng tin như sau: Ngồi việc tìm thơng tin về domain như trên, chúng ta cĩ thể sử dụng các tiện ích Reverse IP domain lookup để cĩ thể xem thử trên IP của mình cĩ bao nhiêu host chung với mình. Vào link sau đây để sử dụng tiện ích này. Việc tìm kiếm được thơng tin này rất cần thiết với Hacker, bởi vì dựa vào thơng tin sử dụng chung Server này, Hacker cĩ thể thơng qua các Website bị lỗi trong danh sách trên và tấn cơng vào Server từ đĩ kiểm sốt tất cả các Website được hosting trên Server. Bước 2: Tìm thơng tin email Trong bài thực hành này, chúng ta sử dụng phần mềm “1st email address spider” để tìm kiếm thơng tin về các email. Hacker cĩ thể sử dụng phần mềm này để thu thập thêm thong tin về mail, hay lọc ra các đối tượng email khác nhau, tuy nhiên bạn cĩ thể sử dụng tool này để thu thập thêm thơng tin nhằm mục đích marketing, ví dụ bạn cần tìm thơng tin của các email cĩ đuơi là @vnn.vn hay @hcm.vnn.vn để phục cho việc marketing sản phẩm. Ta cĩ thể cấu hình việc sử dụng trang web nào để lấy thơng tin , ví dụ sử dụng trang google.com để tìm kiếm. Sau đĩ đánh từ khĩa vnn.vn vào tag keyword Sau đĩ chúng ta đã cĩ được 1 list mail nhờ sử dụng trương trình này. BÀI 2 : SCANNING Scanning hay cịn gọi là quét mạng là bước khơng thể thiếu được trong quá trình tấn cơng vào hệ thống mạng của hacker. Nếu làm bước này tốt Hacker sẽ mau chĩng phát hiện được lỗi của hệ thống ví dụ như lỗi RPC của Window hay lỗi trên phầm mềm dịch vụ web như Apache v.v. Và từ những lỗi này, hacker cĩ thể sử dụng những đoạn mã độc hại(từ các trang web) để tấn cơng vào hệ thống, tồi tệ nhất lấy shell. Phần mềm scanning cĩ rất nhiều loại, gồm các phầm mềm thương mại như Retina, GFI, và các phần mềm miễn phí như Nmap,Nessus. Thơng thường các ấn bản thương mại cĩ thể update các bug lỗi mới từ internet và cĩ thể dị tìm được những lỗi mới hơn. Các phần mềm scanning cĩ thể giúp người quản trị tìm được lỗi của hệ thống, đồng thời đưa ra các giải pháp để sửa lỗi như update Service patch hay sử dụng các policy hợp lý hơn. Bước 1: Sử dụng Phần mềm Nmap Trước khi thực hành bài này, học viên nên tham khảo lại giáo trình lý thuyết về các option của nmap. Chúng ta cĩ thể sử dụng phần mềm trong CD CEH v5, hay cĩ thể download bản mới nhất từ website: www.insecure.org. Phần mềm nmap cĩ 2 phiên bản dành cho Win và dành cho Linux, trong bài thực hành về Nmap, chúng ta sử dụng bản dành cho Window. Để thực hành bài này, học viên nên sử dụng Vmware và boot từ nhiều hệ điều hành khác nhau như Win XP sp2, Win 2003 sp1, Linux Fedora Core, Win 2000 sp4,v.v. Trước tiên sử dụng Nmap để do thám thử xem trong subnet cĩ host nào up và các port các host này mở, ta sử dụng lệnh Nmap –h để xem lại các option của Nmap, sau đĩ thực hiện lệnh “Nmap –sS 10.100.100.1-20”. Và sau đĩ được kết quả sau: C:\Documents and Settings\longdt>nmap -sS 10.100.100.1-20 Starting Nmap 4.20 ( ) at 2007-08-02 10:27 Pacific Standard Time Interesting ports on 10.100.100.1: Not shown: 1695 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind MAC Address: 00:0C:29:09:ED:10 (VMware) Interesting ports on 10.100.100.6: Not shown: 1678 closed ports PORT STATE SERVICE 7/tcp open echo 9/tcp open discard 13/tcp open daytime 17/tcp open qotd 19/tcp open chargen 23/tcp open telnet 42/tcp open nameserver 53/tcp open domain 80/tcp open http 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds 1025/tcp open NFS-or-IIS 1026/tcp open LSA-or-nterm 1027/tcp open IIS 1030/tcp open iad1 2105/tcp open eklogin 3389/tcp open ms-term-serv 8080/tcp open http-proxy MAC Address: 00:0C:29:59:97:A2 (VMware) Interesting ports on 10.100.100.7: Not shown: 1693 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds 1025/tcp open NFS-or-IIS MAC Address: 00:0C:29:95:A9:03 (VMware) Interesting ports on 10.100.100.11: Not shown: 1695 filtered ports PORT STATE SERVICE 139/tcp open netbios-ssn 445/tcp open microsoft-ds MAC Address: 00:0C:29:A6:2E:31 (VMware) Skipping SYN Stealth Scan against 10.100.100.13 because Windows does not support scanning your own machine (localhost) this way. All 0 scanned ports on 10.100.100.13 are Interesting ports on 10.100.100.16: Not shown: 1689 closed ports PORT STATE SERVICE 21/tcp open ftp 25/tcp open smtp 80/tcp open http 135/tcp open msrpc 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 1433/tcp open ms-sql-s MAC Address: 00:0C:29:D6:73:6D (VMware) Interesting ports on 10.100.100.20: Not shown: 1693 closed ports PORT STATE SERVICE 135/tcp open msrpc 445/tcp open microsoft-ds 1000/tcp open cadlock 5101/tcp open admdog MAC Address: 00:15:C5:65:E3:85 (Dell) Nmap finished: 20 IP addresses (7 hosts up) scanned in 21.515 seconds Trong mạng cĩ tất cả 7 host gồm 6 máy Vmware và 1 PC DELL. Bây giờ bước tiếp theo ta tìm kiếm thơng tin về OS của các Host trên bằng sử dụng lệnh “ Nmap –v -O ip address” . C:\Documents and Settings\longdt>nmap -vv -O 10.100.100.7 (xem chi tiết Nmap quét) Starting Nmap 4.20 ( ) at 2007-08-02 10:46 Pacific Standard Time Initiating ARP Ping Scan at 10:46 Scanning 10.100.100.7 [1 port] Completed ARP Ping Scan at 10:46, 0.22s elapsed (1 total hosts) Initiating Parallel DNS resolution of 1 host. at 10:46 Completed Parallel DNS resolution of 1 host. at 10:46, 0.01s elapsed Initiating SYN Stealth Scan at 10:46 Scanning 10.100.100.7 [1697 ports] Discovered open port 1025/tcp on 10.100.100.7 Discovered open port 445/tcp on 10.100.100.7 Discovered open port 135/tcp on 10.100.100.7 Discovered open port 139/tcp on 10.100.100.7 Completed SYN Stealth Scan at 10:46, 1.56s elapsed (1697 total ports) Initiating OS detection (try #1) against 10.100.100.7 Host 10.100.100.7 appears to be up ... good. Interesting ports on 10.100.100.7: Not shown: 1693 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds 1025/tcp open NFS-or-IIS MAC Address: 00:0C:29:95:A9:03 (VMware) Device type: general purpose Running: Microsoft Windows 2003 OS details: Microsoft Windows 2003 Server SP1 OS Fingerprint: OS:SCAN(V=4.20%D=8/2%OT=135%CT=1%CU=36092%PV=Y%DS=1%G=Y%M=0 00C 29%TM=46B2187 OS:3%P=i686-pc-windowswindows) SEQ(SP=FF%GCD=1%ISR=10A%TI=I%II=I%SS=S%TS=0) OS:OPS(O1=M5B4NW0NNT00NNS%O2=M5B4NW0NNT00NNS%O3=M5B4NW0NNT0 0%O4=M5B4NW0NNT0 OS:0NNS%O5=M5B4NW0NNT00NNS%O6=M5B4NNT00NNS)WIN(W1=FAF0%W2=F AF0%W3=FAF0%W4=F OS:AF0%W5=FAF0%W6=FAF0)ECN(R=Y%DF=N%T=80%W=FAF0%O=M5B4NW0NN S%CC=N%Q=)T1(R=YOS:%DF=N%T=80%S=O%A=S+%F=AS%RD=0%Q=)T2(R=Y% DF=N%T=80%W=0%S=Z%A=S%F=AR%O=%RD OS:=0%Q=)T3(R=Y%DF=N%T=80%W=FAF0%S=O%A=S+%F=AS%O=M5B4NW0NNT 00NNS%RD=0%Q=)T4OS:(R=Y%DF=N%T=80%W=0%S=A%A=O%F=R%O=%RD=0%Q =)T5(R=Y%DF=N%T=80%W=0%S=Z%A=S+% OS:F=AR%O=%RD=0%Q=)T6(R=Y%DF=N%T=80%W=0%S=A%A=O%F=R%O=%RD=0 %Q=)T7(R=Y%DF=N%OS:T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y %DF=N%T=80%TOS=0%IPL=B0%UN=0%RIP OS:L=G%RID=G%RIPCK=G%RUCK=G%RUL=G%RUD=G)IE(R=Y%DFI=S%T=80%T OSI=Z%CD=Z%SI=S% OS:DLI=S) Network Distance: 1 hop TCP Sequence Prediction: Difficulty=255 (Good luck!) IPID Sequence Generation: Incremental OS detection performed. Please report any incorrect results at . Nmap finished: 1 IP address (1 host up) scanned in 3.204 seconds Raw packets sent: 1767 (78.460KB) | Rcvd: 1714 (79.328KB) Ta cĩ thể xem các figerprinting tại “ C:\Program Files\Nmap\nmap-os-fingerprints” Tiếp tục với những máy cịn lại. C:\Documents and Settings\longdt>nmap -O 10.100.100.1 Starting Nmap 4.20 ( ) at 2007-08-02 10:54 Pacific Standard Time Interesting ports on 10.100.100.1: Not shown: 1695 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind MAC Address: 00:0C:29:09:ED:10 (VMware) Device type: general purpose Running: Linux 2.6.X OS details: Linux 2.6.9 - 2.6.12 (x86) Uptime: 0.056 days (since Thu Aug 02 09:34:08 2007) Network Distance: 1 hop OS detection performed. Please report any incorrect results at . Nmap finished: 1 IP address (1 host up) scanned in 2.781 seconds Tuy nhiên cĩ 1 số host Nmap khơng thể nhận diện ra như sau: C:\Documents and Settings\longdt>nmap -O 10.100.100.16 Starting Nmap 4.20 ( ) at 2007-08-02 10:55 Pacific Standard Time Interesting ports on 10.100.100.16: Not shown: 1689 closed ports PORT STATE SERVICE 21/tcp open ftp 25/tcp open smtp 80/tcp open http 135/tcp open msrpc 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 1433/tcp open ms-sql-s MAC Address: 00:0C:29:D6:73:6D (VMware) No exact OS matches for host (If you know what OS is running on it, see ). TCP/IP fingerprint: OS:SCAN(V=4.20%D=8/2%OT=21%CT=1%CU=35147%PV=Y%DS=1%G=Y%M=00 0C29%TM=46B21A94OS:%P=i686-pc-windowswindows) SEQ(SP=FD%GCD=2%ISR=10C%TI=I%II=I%SS=S%TS=0)SOS:EQ(SP=FD%GC D=1%ISR=10C%TI=I%II=I%SS=S%TS=0)OPS(O1=M5B4NW0NNT00NNS%O2=M 5BOS:4NW0NNT00NNS%O3=M5B4NW0NNT00%O4=M5B4NW0NNT00NNS%O5=M5B 4NW0NNT00NNS%O6=M5OS:B4NNT00NNS)WIN(W1=FAF0%W2=FAF0%W3=FAF0 %W4=FAF0%W5=FAF0%W6=FAF0)ECN(R=Y%DOS:F=Y%T=80%W=FAF0%O=M5B4 NW0NNS%CC=N%Q=)T1(R=Y%DF=Y%T=80%S=O%A=S+%F=AS%RD=0OS:%Q=)T2 (R=Y%DF=N%T=80%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF=Y%T=80 %W=FAF0OS:%S=O%A=S+%F=AS%O=M5B4NW0NNT00NNS%RD=0%Q=)T4(R=Y%D F=N%T=80%W=0%S=A%A=O%F=OS:R%O=%RD=0%Q=)T5(R=Y%DF=N%T=80%W=0 %S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=N%TOS:=80%W=0%S=A%A=O%F =R%O=%RD=0%Q=)T7(R=Y%DF=N%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=OS:0 %Q=)U1(R=Y%DF=N%T=80%TOS=0%IPL=38%UN=0%RIPL=G%RID=G%RIPCK=G %RUCK=G%RUL=OS:G%RUD=G)IE(R=Y%DFI=S%T=80%TOSI=S%CD=Z%SI=S%D LI=S) Network Distance: 1 hop OS detection performed. Please report any incorrect results at . Nmap finished: 1 IP address (1 host up) scanned in 12.485 seconds Tuy nhiên ta cĩ thể nhận diện rằng đây là 1 Server chạy dịch vụ SQL và Web Server,bây giờ ta sử dụng lệnh “ Nmap –v –p 80 sV 10.100.100.16” để xác định version của IIS. C:\Documents and Settings\longdt>nmap -p 80 –sV 10.100.100.16 Starting Nmap 4.20 ( ) at 2007-08-02 11:01 Pacific Standard Time Interesting ports on 10.100.100.16: PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS webserver 5.0 MAC Address: 00:0C:29:D6:73:6D (VMware) Service Info: OS: Windows Service detection performed. Please report any incorrect results at ure.org/nmap/submit/ . Nmap finished: 1 IP address (1 host up) scanned in 6.750 seconds Vậy ta cĩ thể đốn được phần nhiều host là Window 2000 Server. Ngồi việc thực hành trên chúng ta cĩ thể sử dụng Nmap trace, lưu log v.v Bước 2: Phát hiện các điểm yếu Sử dụng phần mềm Retina để phát hiện các vulnerabilities và tấn cơng bằng Metaesploit framework.Retina của Ieye là phần mềm thương mại(cũng như GFI, shadow v.v ) cĩ thể update các lỗ hỗng 1 cách thường xuyên và giúp cho người Admin hệ thống cĩ thể đưa ra những giải pháp để xử lý. Bây giờ ta sử dụng phần mềm Retina để dị tìm lỗi của máy Win 2003 Sp0(10.100.100.6) Report từ chương trình Retina: TOP 20 VULNERABILITIES Ta liệt kê TOP 20 vulnerabilities trên mạng Rank Vulnerability Name Count 1. echo service 1 2. ASN.1 Vulnerability Could Allow Code Execution 1 3. Windows Cumulative Patch 835732 Remote 1 4. Null Session 1 5. No Remote Registry Access Available 1 6. telnet service 1 7. DCOM Enabled 1 8. Windows RPC Cumulative Patch 828741 Remote 1 9. Windows RPC DCOM interface buffer overflow 1 10. Windows RPC DCOM multiple vulnerabilities 1 11. Apache 1.3.27 0x1A Character Logging DoS 1 TOP 20 OPERATING SYSTEMS The following is an overview of the top 20 operating systems on your network. 12. Apache 1.3.27 HTDigest Command Execution 1 13. Apache mod_alias and mod_rewrite Buffer Overflow 1 14. ApacheBench multiple buffer overflows 1 15. HTTP TRACE method supported 1 TOP 20 OPEN PORTS The following is an overview of the top 20 open ports on your network. Rank Port Number Description Count 1. TCP: 7 ECHO Echo 1 2. TCP: 9 DISCARD - Discard 1 3. TCP: 13 DAYTIME - Daytime 1 4. TCP: 17 QOTD - Quote of the Day 1 5. TCP: 19 CHARGEN - Character Generator 1 6. TCP: 23 TELNET - Telnet 1 7. TCP: 42 NAMESERVER / WINS - Host Name Server 1 8. TCP: 53 DOMAIN - Domain Name Server 1 9. TCP: 80 WWW-HTTP - HTTP 1 10. TCP: 135 RPC-LOCATOR - RPC (Remote Procedure Call) Location Service 1 11. TCP: 139 NETBIOS-SSN - NETBIOS 1 12. TCP: 445 MICROSOFT-DS - Microsoft-DS 1 13. TCP: 1025 LISTEN - listen 1 14. TCP: 1026 NTERM - nterm 1 15. TCP: 1030 IAD1 - BBN IAD 1 16. TCP: 2103 ZEPHYR-CLT - Zephyr Serv-HM Conncetion 1 17. TCP: 2105 EKLOGIN - Kerberos (v4) Encrypted RLogin 1 18. TCP: 3389 MS RDP (Remote Desktop Protocol) / Terminal Services 1 19. TCP: 8080 Generic - Shared service port 1 20. UDP: 7 ECHO - Echo 1 Như vậy ta đã xác định hệ điều hành của máy 10.100.100.6, các Port mở của hệ thống và các lỗi của hệ thống. Đây là thơng tin cần thiết để người Admin nhận diện lỗi và vá lỗi Trong Top 20 vulnerabilities ta sẽ khai thác bug lỗi thứ 10 là RPC DCOM bằng chương trinh Metaesploit framework(CD CEH v5). Ta cĩ thể kiểm tra các thơng tin lỗi này trên chính trang của Ieye hay securityfocus.com, microsoft.com. Ta sử dụng giao diện console của Metaesploit để tìm bug lỗi hợp với chương trình Retina vừa quét được. Rank Operating System Name Count 1. Windows Server 2003 1 Ta thấy cĩ thể nhận thấy bug lỗi msrpc_dcom_ms03_026.pm được liệt kê trong phần exploit của metaesploit. Bây giờ ta cĩ thể khai thác lỗi này. Như vậy sau khi khai thác ta đã cĩ được shell của máy Win 2003, bây giờ ta cĩ thể upload backdoor hay lấy những thơng tin cần thiết trong máy này(vấn đề này sẽ được bàn ở những chương sau). Kết luận: Phần mềm scanning rất quan trọng với Hacker để cĩ thể phát hiện lỗi của hệ thống, sau khi xác định lỗi Hacker cĩ thể sử dụng Framework cĩ sẵn hay code cĩ sẵn trên Internet để cĩ thể chiếm quyền sử dụng của máy mục tiêu. Tuy nhiên đây cũng là cơng cụ hữu ích của Admin hệ thống, phần mềm này giúp cho người Admin hệ thống đánh giá lại mức độ bảo mật của hệ thống mình và kiểm tra liên tục các bug lỗi xảy ra. Phần 1 : Hiện thực các thuật giải cơ bản các phép tốn modulo (dùng C,C++). (5 tiết) (Các đoạn code trong bài tập mang tính tham khảo , khơng phải là bài mẫu . Sinh viên phải tự viết code của mình.) Bài 1 : Kiểm tra số nguyên tố : Input : số nguyên x Output: kiểm tra x là số nguyên tố, ra thơng báo Code tham khảo #include #include void main() { clrscr(); int x , n; cout>x; n=2; while(x%n>0) { n++; } if (n==x ) cout<<"La so nguyen to"; else cout<<"Khongla so NT"; getch(); } Bài 2 . Tạo N số nguyên tố đầu tiên Input : N – số nguyên Output: Tạo các số nguyên tố nhỏ hơn N Tính các số nguyên tố nhỏ hơn 20.000.000 Code tham khảo #include #include #define N 100 int i,j,k; long int q,r,n,pr[N+1]; int main() { pr[1]=2;n=3;j=1; label1:j++;pr[j]=n; if (j==N) goto label4; label2: n+=2;k=2; label3: q=n/pr[k];r=n%pr[k]; if(r==0) goto label2; if (q<=pr[k]) goto label1; k++;goto label3 ; label4: for(i=1;i<=N;i++) { printf("%1d ",pr[i]); if(i%10==0) printf(" "); } getchar(); return(n,j,k); }/*main*/ Bài 3 : Biểu diễn theo cơ số B Input : Hai số nguyên dương a ,b Output : Biểu diễn số nguyên a theo cơ số b=2,4,16,32 Code tham khảo #include #include int a,b; long repre(int a,int b); long repre0(int a,int b); void main() { a=12;b=2; repre(a,b); a=8;b=4; repre(a,b); a=15245;b=32; repre(a,b); a=748;b=16; repre(a,b); a=14;b=2; repre0(a,b); getchar(); }/* main */ long repre(int a,int b) { int n,i,A[20];long x,q; n=0;q=a/b;A[n]=a%b; while(q>0) { n++;x=q;q=x/b;A[n]=x%b; }/* end while */ printf("a=%1d b=%1d n=%1d\n " ,a,b,n); for(i=0;i<=n;i++) printf(" A[%d]=%1d\n ",i,A[i]); } /* b-representation */ long repre0(int a,int b) { int A0,A1; A0=a%b;A1=(a/b)%b; printf("a=%ld d=%1d A0=%1d A1=%1d ",a,b,A0,A1); }/* b-representation */ Bài 4 : Cộng hai số biểu diễn theo cơ số B Input : Hai số nguyên dương x,y được biểu diễn theo cơ số B Output :Tổng x+y được biểu diễn theo B Code tham khảo #include #include long a,b,x,y,z,t; int A[100],X[100],Y[100],Z[100],i,n,N; long repre(long a,long b); long add(long x,long y); void main() { x=2748;y=659260;b=32; a=x; /*printf("a=%d b=%d x=%d y=%d \n",a,b,x,y);*/ repre(a,b); N=n; for(i=0;i<=n;i++) X[i]=A[i]; a=y;repre(a,b);if(N<n) N=n; for(i=0;i<=n;i++) Y[i]=A[i]; printf("x=%ld y=%ld b=%ld N=%d \n",x,y,b,N); for(i=0;i<=N;i++) printf("X[%d]=%d Y[%d]=%d \n",i,X[i],i,Y[i]); add(x,y); for(i=0;i<=N;i++) printf("Z[%d]=%d \n",i,Z[i]); /* verification */ z=Z[0];t=1; fo r(i=1;i<=N+1;i++) {t *=b;z+=(Z[i]*t);} pr intf("z=%ld x+y=%ld \n",z,x+y);getchar(); }/* main */ long repre(long a,long b) { long q,qq ; n=0 ; q =a/b ; A[n]=a%b ; while(q>0) {n++ ; qq=q ; q=qq/b ; A[n]=qq%b;} } /* b - representation */ long add(long x,long y) { int ii,c=0,tem; /* c is the carry digit */ for(ii=0;ii<=n;ii++) { tem=(X[ii]+Y[ii]+c); if(tem<b) {Z[ii]=tem;c=0;} else {Z[ii]=tem-b;c=1;} }/* ii */ Z[N+1]=c; }/* add */ Bài 5 Nhân hai số theo cơ số B Input : Hai số nguyên dương x,y được biểu diễn theo cơ số B>= 2 cĩ độ dài N+1 digist Output :Tích x*y được biểu diễn theo B cĩ độ dài N+M+2 Code tham khảo # include # include long a,x,y,z,t,bb,b,k,B[20] ; int A[20],X[20],Y[20],Z[20],i,n,N,M,A0,A1; long repres(long x,long b); long mult(long x,long y); void main () /* cr5i. C , 21 / 6 / 1998 */ { x=659260 ; y=2748 ; b=32 ; repres(x,b) ; N=n ; for(i=0 ; i<=n ; i++ ) X[i]=A[i] ; repres(y,b) ; N=n ; for(i=0 ; i<=n ; i++) Y[i]=A[i] ; printf("x=%ld y=%ld b=%ld N=%ld M=%ld ",x,y,b,N,M); for (i=0 ; i<=N ;i++) printf("X[%d]=%d Y[%d]=%d",i,X[i],i,Y[i]); mult (x,y) ; for (i=0 ; i<=N+M+1 ; i++) printf("Z[%d]=%d ",i,Z[i]); /* verification */ z=Z[0] ; t=1 ; for(i=0 ; i<=(N+M+1) ; i++) {t*=b ; z+=(Z[i]*t) ;} printf ( "z=%ld x*y=%ld" ,z,x*y ) ; } /*MAIN*/ long mult (long x,long y) { int ii,jj,ca ; for(ii=0 ; ii<= N+M+1 ; ii++ ) Z[ii]=0 ; for (ii=0 ; ii<=M ; ii++) { ca=0 ; for(jj=0 ; jj<=N ; jj++ ) { a=Z[ii+jj]+(X[jj]*Y[ii])+ca ; k=1 ; while(k*b<=a) k++ ; k-- ; A1=k ; A0=a-k*b; Z[ii+jj]=A0 ; ca=A1; } /* jj */ Z[ii+N+1]=A1; } /* ii */ } /* mult */ long a0; int b0 ; long repes (long a0 ,int b0 ) { n=0 ; bb=1 ; B[0]=1 ; while(bb<a0) {bb*=b0 ; n++ ; B[n]=bb ; } n-- ; for (i=n ; i>0 ; i--) { bb=B[i] ; k=1 ; while(( k*bb) <= a0) k++ ; k--; A[i]=k ; a0-=k*bb ; } A[0]=a0; } /* b - repres*/ Bài 6: Thuật giải Beazout tính gcd của a & b Input : Hai số nguyên dương a&b Output :Tính gcd(a,b) (Dùng beazout) Code tham khảo #include #include long A,B; long bezout(long A,long B); void main() /*main*/ { A=9; B=0; bezout(A,B); A=13; B=17;bezout(A,B); A=21; B=36; bezout(A,B); A=2145378312; B=1256993; bezout(A,B); getchar(); } /*Main*/ long a,b; long bezout(long a,long b) { long d,q,r,x,x1,x2,y,y1,y2,tem; if (b==0) { d=a;x=1;y=0; } else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b;r=a-q*b;x=x2-q*x1;y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; } d=a;x=x2;y=y2; } tem=A*x+B*y-d; /* if (y<0) y=A+y;*/ printf("A=%ld B=%ld d=%ld x=%ld y=%ld tem=%ld ",A,B,d,x,y,tem); return(a,b); }/*bezout*/ Bài 7 : Tính lũy thừa Modulo Input : Cho trước x,p,m nguyên dương Output : Tìm y = x p modm Code tham khảo #include #include /*(X^p)mod m*/ long p,A0,xx,yy,m,k,bb,B[40],A[40],X[40],Y[40],PP,Q[40],MP(); int i,n,N,M; double tem; long ME(long xx,long m,long p); void main() { xx=5;m=1234;p=596; printf("xx=%ld m=%ld p=%ld \n",xx,m,p);getchar(); ME(xx,m,p); xx=10083255;m=124540019;p=12496; ME(xx,m,p); printf("xx=%ld m=%ld p=%ld \n",xx,m,p); getchar(); } /* Main */ long s; long BR(long s) { int ii;long x,q; ii=0;x=s;q=(x>>1);A[ii]=x-(q<<1); while(q>0) { ii++;x=q;q=(x>>1);A[ii]=x-(q<<1); } n=ii; } /*BR-bit repres*/ long a0,b0; long repres(long a0,long b0) { n=0;bb=1;B[0]=1; while(bb<a0) {bb*=b0;n++;B[n]=bb;} n--; for(i=n;i>0;i--) { bb=B[i]; k=1;while((k*bb)<=a0) k++;k--; A[i]=k;a0-=k*bb; } A[0]=a0;/*A[0]=x,y mod m */ } long x,y,b; long MP(long x,long y,long b) { long P;int j; BR(y);M=n; /*Bit repres of y*/ for(j=0;j<=M;j++) Y[j]=A[j]; /*for(j=0;j<=M;j++) printf("Y[%d]=%ld ",j,Y[j]);*/ if(Y[0]>0) P=x;else P=0; for(j=1;j<=M;j++) { tem=2.0*x; if(tem>=b) tem-=b; x=(long)tem; if(Y[j]>0) { tem+=P; if(tem>=b) P=(long)(tem-b); else P=(long)tem; } } /*j*/ return (P); } long ME(long xx,long m,long p) { BR(p);N=n; for(i=0;i<=N;i++) Q[i]=A[i]; for(i=0;i<=N;i++) printf("Q[%d]=%ld \n",i,Q[i]);getchar(); A0=1; if(p>0) { A0=1; for(i=N;i>=0;i--) { A0=MP(A0,A0,m); if(Q[i]>0) A0=MP(A0,xx,m); printf("i=%d A0=%ld \n",i,A0); }/*i*/ } printf("A0=%ld \n",A0); getchar(); } /*ME*/ Bài 8 : Thực hiện thuật giải lũy thừa nhanh ( Thuật giả Chivers) Input: a, m, N. Output: a m mod N. Begin kbk-1 0. j = 0, kq = a; while (k>=j) { if (bj==1) kq = (kq * a) mod N; a = (a * a) mod N; j = j + 1; } return kq; -------------- Code tham khảo long modexp(long a, long x, long n) { long r = 1; while (x > 0) { if (x % 2 == 1) /* is x odd? */ r = (r * a) % n; a = (a*a) % n; x /= 2; } return r; } Bài 9 . Cho một số nguyên a (ord(a)) trên trường Z*N : a.Viết chương trình tính ord(a) trên trường Z*26 ,Z*32 ,Z*64 b.Tính φ(N) c.Xác định các số nguyên thủy trong các trường số trên. Bài 10 . Tính lũy thừa modulo nghich đảo Input :Hai số nguyên dương a&b Output :Tìm một số y≡a-1 modb ( Thực chất là tìm nghiệm của pt bậc nhất : ay - bx =1) Code tham khảo #include #include long A,B; long inverse(long B, long A); void main() { B=28; A=25; inverse(B,A); B=13; A=3; inverse(B,A); B=12; A=5; inverse(B,A); B=13; A=3; inverse(B,A); getchar(); } long a,b; long inverse(long b,long a) { long d,q,r,x,x1,x2,y,y1,y2,tem; if (b==0) { d=a;x=1;y=0; else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b;r=a-q*b;x=x2-q*x1;y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; } d=a;x=x2;y=y2; } tem=A*x+B*y-d; if (y<0) y=A+y; printf("A=%ld B=%ld d=%ld x=%ld y=%ld tem=%ld \n ",A,B,d,x,y,tem); } ================================= Phần 2 : Hiện thực các thuật giải mật mã đối xứng (C,C++)(10 tiết) Bài1 : Hiện thực thuật giải hệ mật Cesar V – k) mod N. B ng c uyển đổ g ữ ý tự ngl s và số C e t /* Mã Cesar */ include "stdio.h" #include "stdlib.h" #include "string.h" #include "stack-c.h" int Caesar(char*ciphertext) { int i; int ciphertextLength; char *plaintext; //k=3 ciphertextLength = strlen(ciphertext); plaintext = (char *)malloc(ciphertextLength+1); strcpy(plaintext,ciphertext); for( i=0 ; plaintext[i]!='\0'; i++) //encrypt the plaintext { if( plaintext[i]>='A' && plaintext[i]<= 'Z') //to clear characters one by one after the three-shift ciphertext[i]='A'+( plaintext[i]-'A'+ 3 )%26; else if( plaintext[i]>='a' && plaintext[i]<= 'z' ) ciphertext[i]='a'+( plaintext[i]-'a'+ 3 )%26; else ciphertext[i]=plaintext[i]; } ciphertext[i]='\0';//marks the end of the string a b c d e f g h i j k l m 1 2 3 4 5 6 7 8 9 10 11 12 13 n o p q r s t u v w x y z 14 15 16 17 18 19 20 21 22 23 24 25 26 free(plaintext);//release space return 0; } /* Giải mã Cesar */ /******************************************************************* /* Description : Caesar Decryption Function */ /******************************************************************/ #include "stdlib.h" #include "string.h" #include "stack-c.h" #include "stdio.h" int DeCaesar(char *plaintext) { int i; int plaintextLength; int ciphertextLength; char *ciphertext; plaintextLength = strlen(plaintext); ciphertext = (char *)malloc(plaintextLength+1); strcpy(ciphertext,plaintext); ciphertextLength = strlen(ciphertext); for( i=0 ; ciphertext[i]!='\0'; i++) //to decrypt ciphertext { if( ciphertext[i]>='A' && ciphertext[i]<= 'Z') //for each character ciphertext forward three plaintext[i]='A' + ( ciphertext[i] - ('A') - 3 + 26) %26; else if( ciphertext[i] >= 'a' && ciphertext[i]<= 'z' ) plaintext[i]='a' + ( ciphertext[i] - ('a') - 3 + 26) %26; else plaintext[i]=ciphertext[i]; } plaintext[i]='\0';//marks the end of the string free(ciphertext);//release space return 0; } Bài 2 : Hiện thực thuật giải hệ mật Vigener ỗ є Zn c đ à là t u ý tự c đ à 1k2 M. ể c t àn c c đ n đ à và c uyển t àn số t ng ứng c c ng t ng ng c ữ c c ng n 1 x2 M. EK(X) = (x1 + k1, x2 + k2 M + kM) mod N DK(Y) = (y1 - k1, y2 - k2 yM - kM v và y1y2yM là n C e t /* Mã hĩa Vigenere*/ #include "stack-c.h" #include "stdio.h" #include "string.h" #include "stdlib.h" int Vigenere(char *key,char *ciphertext) { int i,j,keyLength,plaintextLength; int IntegerCipher,IntegerPlain,IntegerKey; int ciphertextLength; char *plaintext; ciphertextLength = strlen(ciphertext); plaintext=(char *)malloc(ciphertextLength+1); strcpy(plaintext,ciphertext); keyLength = strlen(key); plaintextLength = strlen(plaintext); for(i = 0,j = 0;i < plaintextLength;i ++,j ++) { if(j % keyLength == 0 && j!= 0) j = 0; IntegerPlain = plaintext[i] - 'a'; IntegerKey = key[j] - 'a'; // //Transform char into integer IntegerCipher = IntegerPlain + IntegerKey % 26; //Compute cipertext if(IntegerCipher > 25) IntegerCipher -= 26; ciphertext[i] = IntegerCipher + 'a'; //Transform integer into char } ciphertext[i] = '\0'; free(plaintext); return 0; } /* Giải mã Vigenere */ /************************************************************** /* Describe : DeVirginia Cipher Function /****************************************************************/ #include "stack-c.h" #include "stdio.h" #include "string.h" #include "stdlib.h" //#include "sciprint.h" int DeVigenere(char *key,char *plaintext) { int i,j,keyLength,ciphertextLength; int IntegerPlain,IntegerCipher,IntegerKey; int plaintextLength; char *ciphertext; plaintextLength = strlen (plaintext); ciphertext = (char *)malloc(plaintextLength+1); strcpy(ciphertext,plaintext); keyLength = strlen(key); ciphertextLength = strlen(ciphertext); // sciprint("character string keyLength %d\n",keyLength); //sciprint("character string ciphertextLength %d\n",ciphertextLength); for(i = 0,j = 0;i < ciphertextLength;i ++,j ++) { if(j % keyLength == 0 && j!= 0) j = 0; IntegerCipher = ciphertext[i] - 'a'; IntegerKey = key[j] - 'a'; // Transform interger into char IntegerPlain = IntegerCipher - IntegerKey % 26; if(IntegerPlain < 0) IntegerPlain += 26; plaintext[i] = IntegerPlain + 'a'; // Transform interger into char } plaintext[i] = '\0'; free(ciphertext); return 0; } Bài 3 : Ch hệ mã Vigenere c C H ỗi M = CJ C R U GBGL K CBDUGV” Bài 4 : Ch hệ mã Vigenere c ã h a u H ngư i ta thu đư c ản mã CVV D ở C KLG BRV ” Bài 5 : Viết chương trình hiện thực hệ mã Affine (trên C, C++) C – ữ ử |A K K { ( N, (a, N) = 1} chữ ừ ( – ừ ( ức sau: EK(x) = (a*x + b) mod N. K ứ ứ ( g chữ -1 ( ( ứ DK( ( - K ứ ứ a*(y - b) mod N tr ữ C e t /* Mã Affine*/ /******************************************************************* ******//* Description : Affine encryption function */ /******************************************************************* ******/ #include "stack-c.h" #include "stdio.h" #include "string.h" #include "stdlib.h" int Affine(int *key1,int *key2,char *c) //parameter Description: clearly a key (integer) key1 key2 ciphertext c { char *a; int clength; int i; char t; clength=strlen(c); a=(char *)malloc(clength+1); //distribution space strcpy(a,c); for( i=0 ; a[i]!='\0' ; i++ ) //to decrypt ciphertext { t=a[i]; if( t>='A' && t<='Z' ) t=t+'a'-'A'; c[i]= ( ( (t-'a') * (*key1) +(*key2) ) % 26 ) +'a'; } c[i]='\0';//marks the end of the string free(a); //release space return 0; } /* Giải mã Affine */ /******************************************************************* ****** /* Description : Affine Decryption Function */ /******************************************************************* ******/ #include "stdio.h" #include "stdlib.h" #include "string.h" #include "stack-c.h" int DeAffine(int *key1,int *key2,char *a) //parameter Description: clearly a key (integer) key1 key2 ciphertext c { char *c; int alength; int n,i,t; alength=strlen(a); c=(char *)malloc(alength+1); //distribution space strcpy(c,a); for( n=2; ; n++ ) if( ( (*key1)*n % 26 ) == 1 ) break; for( i=0; c[i]!='\0'; i++ ) //to decrypt plaintext { t = (c[i]-'a')*n-(15*(*key2) % 26) ; if( t<0 ) t+=26;//mode of negative results for the smallest positive number a[i]=( t % 26 ) + 'a'; } a[i]='\0'; //marks the end of the string free(c); //release space return 0; } Bài 6. Dùng chương trình ở bài tập 5 , giải : 99 K ( 99 ( K ( ( DK ( a-1 * (x – b) mod 99. ử K-1 ( D G R” Bài 7 : Hiện thực thuật giải hệ mã rasnp siti n C e t /********************************************************* /*Mã hĩa transpose */ /*Describe : Transpose Cipher Function /* Input key and plaintext ******************************************************************** *****/ #include "stdio.h" #include "stdlib.h" #include "string.h" #include "stack-c.h" int Transpose(char *key,char *text) { int i,j,k,m; // Define cycle control variables char t; char *SortKey; // temporary storage for plaintext char *TempPlain; // temporary storage for ciphertext char *TempCipher; // storage for plaintext with no space char *NewPlainText; int keyLength; int plainLength; int NewPlainLength; keyLength = strlen(key); plainLength = strlen(text); TempPlain = (char*)malloc(plainLength + 1); TempCipher = (char*)malloc(plainLength + 1); NewPlainText = (char*)malloc(plainLength + 1); SortKey = (char*)malloc(keyLength + 1); strcpy(TempPlain,text); strcpy(SortKey,key); for(i = 0,j = 0;i < plainLength;i ++,j++) { if(text[i] != ' ') NewPlainText[j] = text[i]; else j --; } NewPlainText[j] = '\0'; // Filter spaces NewPlainLength = strlen(NewPlainText); //compute the plaintext with no space for(i = 0;i < keyLength - 1;i ++) { for(j = keyLength - 1;j > i;j --) if(SortKey[j] < SortKey[j - 1]) { t = SortKey[j]; SortKey[j] = SortKey[j - 1]; SortKey[j - 1] = t; } // sort } for(i = 0,m = 0;i < keyLength;i ++) { for(j = 0;j < keyLength;j ++) if(SortKey[i] == key[j]) break; for(k = j;k < NewPlainLength;k += keyLength,m ++) TempCipher[m] = NewPlainText[k]; } TempCipher[m] = '\0'; strcpy(text,TempCipher); free(TempPlain); free(TempCipher); free(NewPlainText); free(SortKey); return 0; } /**************************************************************** /Giải mã transpose /* Describe: DeTranspose Cipher Function /* Input key and ciphertext /****************************************************************/ #include "stdio.h" #include "stdlib.h" #include "string.h" #include "stack-c.h" int DeTranspose(char *key,char *text) { int i,j,k,m; // (Cycle control variables) char t; char *SortKey;// (After sorting, store Pointers to define the key) char *TempPlain; //(Define pointer, temporary storage expressly) char *TempCipher; // (Define pointer, temporary storage ciphertext) int keyLength; //(Key length) int cipherLength; //(Ciphertext length) keyLength = strlen(key); // (Key length calculation) cipherLength = strlen(text); // The calculated parameters, the ciphertext length) SortKey = (char*)malloc(keyLength + 1); // (As the key distribution in space) TempPlain = (char*)malloc(cipherLength + 1); // (As expressly temporary array allocation space) TempCipher = (char*)malloc(cipherLength + 1); // (Plaintext for temporary array allocation space) strcpy(SortKey,key); // (The original value of the key SortKey as the initial value) strcpy(TempCipher,text); // (The parameter, namely the ciphertext into temporary ciphertext array) for(i = 0;i < keyLength - 1;i ++) { for(j = keyLength - 1;j > i;j --) if(SortKey[j] < SortKey[j - 1]) { t = SortKey[j]; SortKey[j] = SortKey[j - 1]; SortKey[j - 1] = t; } // (The elements of SortKey bubbling from sort) } for(i = 0,m = 0;i < keyLength;i ++) { for(j = 0;j < keyLength;j ++) if(SortKey[i] == key[j]) break; // (Calculate the key is the key which columns) for(k = j;k < cipherLength;k += keyLength,m ++) TempPlain[k] = TempCipher[m]; // (In order to fill the corresponding expressly plaintext temporary expressly array) } TempPlain[cipherLength] = '\0'; strcpy(text,TempPlain); // (The deposit into parameter arrays) free(TempPlain); free(TempCipher); free(SortKey); // (Release the space distribution of already) } Bài 8 : Hiện thực thuật giải D ( i tập ớn) Phần 3 : Mật mã khĩa cơng khai ( 15 tiết) Sử dụng các chương trình tính modulo ở phần 1 Bài 1 : Viết chương trình thực hiện thuật giải Knapsack ( Mackle Hellman) ’ = (a’1, a’2, ..., a’N ’N (u, M) = 1 2. Xây dưng Vecto S = (s1, s2, ..., sN i = (si * u) mod M 3. Khĩa: KP = (S, M), KS = (u, u -1 ) 4. Khơng gian ị P = (x1, x2, ..., xn). C ∑ ’ = C * u-1 ’ ’ t ư (x1, x2, ..., xn). Bài 2 : Chương trình mã –dich dùng RSA _ Thuật giải tạo khĩa : Tạ S T ( ặ ư S T ừ KB ể T p&q 3 Tạ  ươ ự ộ N=p*q  ươ φ(N) = (p-1)*(q-1)  Y ầ ( ậ ừ KB  ươ K ( φ  ( φ  ậ ạ  ươ d ≡ e-1 modφ (Dùng Beazout)  Xuấ ặ (e,N) và (d,N) Bài 3 : Chương trình mã –dich dùng RSA _ Mã dịch trên RSA : a. Xác thực thơng điệp - ậ ừ KB ộ ỗ ý ư - ể ý ự - ậ ừ ( ( ủ - ự d mod N  ử - B ậ ( ầ ự K ( ủ ể “ ” “ ” b. Bảo mật thơng điệp - ậ ệ ầ ậ ộ ỗ ý ự ừ KB - ể ỗ ý ự - Lấ ( ủ ậ ệ ừ ặ K - ằ ( ủ ậ e ử - B ậ ( ủ ể ậ ư  OK! Code tham khảo /* m là một số nguyên */ #include #include #include #define I 4 #include long Q[40]; int n,N,M; typedef long vector[I+1]; long MP(long long x,long y,long z); long inverse(long x,long m),ME(long x,long y,long z); long BR(long s); void main() {/*main*/ clrscr(); long q1,p1,M1,x1,phi1,e1,d1,xx,xx1,xx2,xx3, p2,q2,M2,phi2,e2,d2,yy,yy1,yy2,yy3,now0,now,user_time; now0=time(NULL); p1=2699;q1=795659; M1=p1*q1; printf("p1=%ld q1=%ld M1=%ld ",p1,q1,M1); phi1=(p1-1)*(q1-1);e1=3674911; d1=inverse(e1,phi1); printf("phi1=%ld e1=%ld d1=%ld \n",phi1,e1,d1);printf(""); p2=5843;q2=367531;M2=p2*q2;phi2=(p2-1)*(q2-1); e2=3674911;printf("p2=%ld q2=%ld M2=%ld ",p2,q2,M2); d2=inverse(e2,phi2); printf("phi2=%ld e2=%ld d2=%ld \n",phi2,e2,d2);printf(""); xx=12345; xx1=ME(xx,M1,e1);xx2=ME(xx1,M1,e1);xx3=ME(xx2,M1,e1); yy1=ME(xx3,M2,e2);yy2=ME(yy1,M2,e2);yy3=ME(yy2,M2,e2); cprintf("\n KET QUA MA : ",yy3); printf("xx=%ld \n\nxx1=%ld xx2=%ld xx3=%ld \n",xx,xx1,xx2,xx3); printf("yy1=%ld yy2=%ld yy3=%ld \n",yy1,yy2,yy3); yy2=ME(yy3,M2,d2);yy1=ME(yy2,M2,d2);xx3=ME(yy1,M2,d2); xx2=ME(xx3,M1,d1);xx1=ME(xx2,M1,d1);xx=ME(xx1,M1,d1);/* m=c^d modNN=RO */ cprintf("\n KET QUA DICH : ",xx); printf("xx=%ld \n\nxx1=%ld xx2=%ld xx3=%ld \n",xx,xx1,xx2,xx3); printf("yy1=%ld yy2=%ld yy3=%ld \n",yy1,yy2,yy3); now=time(NULL);user_time=now-now0; printf("\nuser_time = %d seconds ",user_time,"seconds");getchar(); }/*main*/ long x0,m0,p0; long ME(long x0,long m0,long p0) { long A0,p1,Z[40];int i1; BR(p0);N=n;for (i1=0;i1<=N;i1++) Z[i1]=Q[i1]; /*for (i1=0;i1<=N;i1++) printf("Q[%d]=%ld \n",i1,Q[i1]);getchar();*/ A0=x0%m0;p1=1;/* A0=x1modMM B pesentation of x1*/ if(p0>0); { if (Z[0]>0) p1=A0; for(i1=1;i1<=N;i1++) { A0=MP(A0,A0,m0); if(Z[i1]>0) p1=MP(A0,p1,m0); }/*i1*/ } return (p1); }/*phep tinh luy thua modulo*/ long s; long BR(long s) { int ii; long x,q; ii=0;x=s;q=(x>>1);Q[ii]=x-(q<<1); while (q>0) { ii++;x=q;q=(x>>1);Q[ii]=x-(q<<1); } n=ii; }/*Bit-Representation,bieu dien x theo bimary*/ long x,y,k; long MP(long x,long y,long k) { int ii;long P,t1,t2,Y[40];double tem;t1=x;t2=y; if(x<0) {x=-x;x=k-(x%k);} else x=x%k; if(y<0) {y=-y;y=k-(y%k);} else y=y%k; if ((x==0)||(y==0)) {P=0;goto label1;} BR(y); M=n; for(ii=0;ii<=M;ii++) Y[ii]=Q[ii]; if(Y[0]>0) P=x; else P=0; for(ii=1;ii<=M;ii++) { tem=2.0*x; if(tem>=k) tem-=k; x=(long)tem; if(Y[ii]>0) { tem+=P; if(tem>=k) P=(long)(tem-k); else P=(long)tem; } }/*ii*/ x=t1; y=t2; label1:return(P); }/*phep nhan modulo*/ long b,a;/*0<b<a,Multicative inverce of b mod a*/ long inverse(long b,long a) { long A,B,d,q,r,x,x1,x2,y,y1,y2,tem; A=a;B=b; /*Dung Beazout*/ if(b==0) { d=a;x=1;y=0; }/*if*/ else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b; r=a-q*b; x=x2-q*x1; y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; }/*while*/ d=a;x=x2;y=y2; }/*else*/ tem=A*x+B*y-d; if(y<0) y=A+y; return(y); }/*inverse*/ /* plain text ’m’ được nhập vào dưới dạng một chuỗi ký tự #include #include #include #include #include #include #include long MP(long long ,long ,long ); //Nhan luy thua long inverse(long ,long ); //Modulo nghich dao long ME(long ,long ,long ); //Luy thua modulo void BR(long ); //Doi sang dang bit (co so 2) int SNT(long); int snt( long); long Bezout (long a, long b);//tinh gcd long Q[40]; int n,N,M; long MP(long long x,long y,long k){ //Nhan luy thua int ii; long P,t1,t2,Y[40]; double tem; t1=x; t2=y; if(x<0){ x = -x; x = k - (x%k); } else x = x%k; if(y<0){ y = -y; y = k - (y%k); } else y = y%k; if(x==0 || y==0){ P=0; return P; } BR(y); M=n; for(ii=0;ii<=M;ii++) Y[ii]=Q[ii]; if(Y[0]>0) P = x; else P = 0; for(ii=1;ii<=M;ii++){ tem=2.0*x; if(tem>=k) tem -= k; x = (long)tem; if(Y[ii] > 0){ tem +=P; if(tem>=k) P = (long)(tem-k); else P = (long)tem; } } x = t1; y = t2; return P; } long inverse(long b,long a){ //Modulo nghich dao long A,q,r,x,x1,x2,y,y1,y2; A = a; if(b == 0){ x = 1; y = 0; } else{ x2 = 1; x1 = 0; y2 = 0; y1 = 1; while(b>0){ q = a/b; r = a - q*b; x = x2 - q*x1; y = y2 - q*y1; a = b;b = r;x2 = x1; x1 = x; y2 = y1; y1 = y; } x = x2; y = y2; } if(y<0) y = A + y; return y; } long ME(long x0,long m0,long p0){ //Tính Luy thua Modulo long A0,p1,Z[40]; int i1; BR(p0); N=n; for(i1=0;i1<=N;i1++) Z[i1] = Q[i1]; A0 = x0%m0; p1 = 1; if(p0>0);{ if(Z[0]>0) p1=A0; for(i1=1;i1<=N;i1++){ A0=MP(A0,A0,m0); if(Z[i1]>0) p1=MP(A0,p1,m0); } } return p1; } void BR(long s){ //Doi sang dang bit (co so 2) int ii; long x,q; ii = 0; x = s; q = (x>>1); Q[ii] = x - (q<<1); while(q>0){ ii++; x = q; q = (x>>1); Q[ii] = x - (q<<1); } n = ii; } int SNT(long n){ if(n == 1 || n == 2) return 1; int i=3;while(n%i!=0)i++;i--; if(n == i) return -1; return 1; } void main(){ clrscr(); long q1,p1,M1,phi1,e1,d1,xx[25]={0},xx1[25]={0},xx2[25]={0},xx3[25]={0}; //tao ngau nhien SNT randomize(); long arr[30]={0},z,y,x; cout<<"\n Day so nguyen to(Ban co the chon!):"; int i=0; for( int j=0;j<50;j++) { if((z=snt(random(10000)))!=0) { arr[i]=z;i++; } } for( j=0;j<i;j++) cout<<setw(10)<<arr[j]; cout<<"\nNHAP CAP SO NGUYEN TO THU NHAT:"; do{ cout>p1; }while(SNT(p1)<0); do{ cout>q1; }while(SNT(q1)<0); M1 = p1*q1; cout<<"p1 = "<<p1<<" q1 = "<<q1<<" M1 = "<<M1<<endl; phi1 = (p1-1)*(q1-1); do{ cout>e1; }while(Bezout(e1,phi1)!=1); d1=inverse(e1,phi1); cout<<" phi1 = "<<phi1<<" e1 = "<<e1<<" d1 = "<<d1; char a[25]; cout<<"\nNHAP VAN BAN CAN MA HOA: "; gets(a); int n= strlen(a); cout<<"chieu dai chuoi = "<<n<<endl; cout<<"\nVAN BAN CAN MA HOA "<<a; for(int ii=0;ii<n;ii++) /*chuyen kt sang so */ { if((a[ii]!=' ')) { xx[ii]= (a[ii] - '0'); } else xx[ii]=a[ii]; } cout<<"\n chuoi sau khi doi thanh so: "<<xx; //Ma hoa for( ii=0;ii<n;ii++) xx1[ii]=ME(xx[ii],M1,e1); for( ii=0;ii<n;ii++) xx2[ii]=ME(xx1[ii],M1,e1); for( ii=0;ii<n;ii++) xx3[ii]=ME(xx2[ii],M1,e1); cout<<"\nKET QUA MA (van ban ma):"<<xx3<<endl; getch(); //giai ma for( ii=0;ii<n;ii++) xx2[ii]=ME(xx3[ii],M1,d1); for( ii=0;ii<n;ii++) xx1[ii]=ME(xx2[ii],M1,d1); for( ii=0;ii<n;ii++) xx[ii]=ME(xx1[ii],M1,d1); // cout<<"\n Sau giai ma (chua doi thanh ky tu):"<<xx; for(ii=0;ii<n;ii++) { if(xx[ii]!=32) a[ii]= char(xx[ii] + '0'); else a[ii]=' '; } cout<<"\nKET QUA DICH (BANG RO): "<<a; getch(); } long Bezout (long a, long b) { long d,q,r,x,x1,x2,y,y1,y2; if (b==0) { d=a; x=1; y=0; } else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b;r=a-q*b;x=x2-q*x1;y=y2-q*y1; a=b; b=r; x2=x1;x1=x;y2=y1; y1=y; } d=a; x=x2;y=y2; } return d; } int snt(long n) { for(int i=2;i<n;i++) { if((n%i)==0) { n=0; break; } } return n; } ================================================= /* Mã hĩa một file text (thu1.txt) dùng RSA*/ #include #include #include #define I 4 #include long Q[40]; FILE *fp1; int n,N,M; long q1,p1,M1,x1,phi1,e1,d1,xx,xx1,xx2,xx3, p2,q2,M2,phi2,e2,d2,yy,yy1,yy2,yy3; typedef long vector[I+1]; long MP(long long x,long y,long z); long inverse(long x,long m),ME(long x,long y,long z); long BR(long s);/*long codage(long x,long y,long z,long t,long v);*/ void main() {/*main*/ long now0,now,user_time,i2=0; clrscr(); now0=time(NULL); p1=2699;q1=795659; M1=p1*q1; printf("p1=%ld q1=%ld M1=%ld ",p1,q1,M1); phi1=(p1-1)*(q1-1);e1=3674911; d1=inverse(e1,phi1); printf("phi1=%ld e1=%ld d1=%ld \n",phi1,e1,d1);printf(""); p2=5843;q2=367531;M2=p2*q2;phi2=(p2-1)*(q2-1); e2=3674911; printf("p2=%ld q2=%ld M2=%ld ",p2,q2,M2); d2=inverse(e2,phi2); printf("phi2=%ld e2=%ld d2=%ld \n",phi2,e2,d2);printf(""); fp1=fopen("a:\thu1.txt","rb"); printf("KET QUA MA : \n"); while(fread(&xx,sizeof(xx),1,fp1)==1) { /*codage(xx,M1,e1,M2,e2);*/ xx1=ME(xx,M1,e1); xx2=ME(xx1,M1,e1);xx3=ME(xx2,M1,e1); yy1=ME(xx3,M2,e2); yy2=ME(yy1,M2,e2);yy3=ME(yy2,M2,e2); i2++;printf("%lx ",yy3); if(i2%7==0)printf(""); } fclose(fp1); now=time(NULL);user_time=now-now0; printf("\n user_time = %d seconds ",user_time,"seconds");getchar(); }/*main*/ long x0,m0,p0; long ME(long x0,long m0,long p0) { long A0,p1,Z[40];int i1; BR(p0);N=n;for (i1=0;i1<=N;i1++) Z[i1]=Q[i1]; /*for (i1=0;i1<=N;i1++) printf("Q[%d]=%ld \n",i1,Q[i1]);getchar();*/ A0=x0%m0;p1=1;/*printf ("A0=%ld N=%d ",A0,N);getchar();/* A0=x1modMM B pesentation of x1*/ if(p0>0); { if (Z[0]>0) p1=A0; for(i1=1;i1<=N;i1++) { A0=MP(A0,A0,m0); if(Z[i1]>0) p1=MP(A0,p1,m0); /*printf("i1=%d A0=%ld p1=%ld \n",i1,A0,p1);*/ }/*i1*/ }/* printf("p1=%ld ",p1); getchar();*/ return (p1); }/*phep tinh luy thua modulo*/ long s; long BR(long s) { int ii; long x,q; ii=0;x=s;q=(x>>1);Q[ii]=x-(q<<1); while (q>0) { ii++;x=q;q=(x>>1);Q[ii]=x-(q<<1); } n=ii; }/*Bit-Representation,bieu dien bit*/ long x,y,k; long MP(long x,long y,long k) { int ii; long P,t1,t2,Y[40]; double tem; t1=x; t2=y; if(x<0) {x=-x;x=k-(x%k); } else x=x%k; if(y<0) {y=-y;y=k-(y%k); } else y=y%k; if ((x==0)||(y==0)) { P=0; goto label1; } BR(y); M=n; for(ii=0;ii<=M;ii++) Y[ii]=Q[ii]; if(Y[0]>0) P=x; else P=0; for(ii=1;ii<=M;ii++) { tem=2.0*x; if(tem>=k) tem-=k; x=(long)tem; if(Y[ii]>0) { tem+=P; if(tem>=k) P=(long)(tem-k); else P=(long)tem; } }/*ii*/ x=t1; y=t2; label1: return(P); }/*phep nhan modulo*/ long b,a;/*0<b<a,Multicative inverse of b mod a*/ long inverse(long b,long a) { long A,B,d,q,r,x,x1,x2,y,y1,y2,tem; A=a;B=b; if(b==0) { d=a;x=1;y=0; }/*if*/ else { x2=1;x1=0;y2=0;y1=1; while (b>0) { q=a/b; r=a-q*b; x=x2-q*x1; y=y2-q*y1; a=b;b=r;x2=x1;x1=x;y2=y1;y1=y; }/*while*/ d=a;x=x2;y=y2; }/*else*/ tem=A*x+B*y-d; if(y<0) y=A+y; return(y); }/*inverse*/ /* long codage(long x, long y ,long z,long t,long v) { }/*codage*/ Bài 4. Bài tổng hợp :Nộp cho giáo viên hướng dẫn (Kèm theo với CD bài tập chuyên đề) HIỆN THỰC CHƯƠNG TRÌNH HỆ BẢO MẬT – XÁC THỰC DÙNG RSA Tạ ươ Bấ (K) – ạ Menu tạo khĩa : Tạ S T ( ặ ư S T ừ BF ể T p&q 3 Tạ ươ ự ộ N=p*q ươ Fi = (p-1)*(q-1) Y ầ ( ậ ừ KB ươ K T F T F  ậ ạ ươ d = e-1 modFi (Dùng Beazout) Xuấ ặ (e,N) và (d,N) V ụ p=3,q=5;p*q=15 ; Fi=(p-1)*(q-1)=8 e = 3 d =38mod15 = 6561mod15 ệ  Tạo khĩa (K)  Xác thực (A)  Bảo mật (C)  Thốt ra ngồi HT (X) X ấ (3,15) và (6,15) T ề Bấ ( Y ầ ậ ầ ự - ậ ừ KB T ự ậ  ể ữ ệ - ậ ừ ( ( ủ - ự d mod N  ử - B ậ ( ầ ự K ủ “ ” ể -- ư “ ” ú Bấ ( ậ ệ ậ ệ ầ ậ “ ” ừ KB Lấ ( ủ ậ ệ ừ ặ K ằ ( ủ ậ e ử B ậ ( ủ ể ậ ư  OK! Thốt ra menu chính Hỏ ụ Ko??? Y ! T ở ề No ! Bye bye! T HĐH

Các file đính kèm theo tài liệu này:

  • pdftailieu.pdf
Tài liệu liên quan