
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53


본문내용
496c6f7665796f75 (16 비트) 이 된다.
위 C1의 복호문은 Iloveyou
아래는 16진수 암호문 2564d997fbaa77e6에 대한 복호문(평문)의 출력입니다.
입력 ==> 암호문 C = 2564d997fbaa77e6(16 자리)
비밀 ==> 비밀키 K = kim12345(맨 뒤 빈자리 포함하여 8 자리)
출력 ==> 복호문 M = Iloveyou(맨 뒤 빈자리 포함하여 8 자리)
class Test_changhee {
public static void main(String arg[]) {
byte[] cipher = {
0,0,1,1,0,0,1,1,
0,0,1,1,0,1,0,1,
0,1,1,1,1,1,1,0,
1,1,1,1,0,0,0,1,
0,1,0,0,1,0,0,1,
1,1,0,0,1,1,0,0,
1,0,1,0,0,1,0,1,
1,1,1,0,1,0,0,1
};
byte[] key = {
1,0,1,1,1,1,0,0,
1,0,0,1,1,1,1,1,
1,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,1,
0,0,1,1,1,1,0,1,
1,0,1,1,1,0,1,0,
1,0,0,1,1,0,1,1,
0,0,1,0,0,1,0,0
};
byte[] key1 = new byte[64];
byte[][] keylist = new byte[16][48];
int i,j;
//키생성
System.out.print("---------------키생성과정---------------");
System.out.println();
System.out.print("원래의 키값 : ");
for(int z=0;z<64;z++) {
System.out.print(key[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
key1 = DesMakey.Pc1(key);
keylist = DesMakey.makey(key1);
//암호화
System.out.print("============암호화과정============");
System.out.println();
System.out.print("원래의 평문 : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
cipher = Des.Ip(cipher); //IP 순열
System.out.print("IP순열 통과후 : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
for(j=0;j<16;j++) { //16라운드 시작
System.out.print((j+1)+"라운드과정(암호화) ");
System.out.println();
cipher = Des.Encrypt(cipher,keylist[j]);
System.out.print((j+1)+"번째 왼쪽 32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.print((j+1)+"번째 오른쪽 32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z+32]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
}
cipher = Des.change(cipher); //최종 스위치
cipher = Des.Ip2(cipher); //역 IP 순열
System.out.print("암호문 : "); //최종 암호문출력
for(int z=0;z<64;z++)
System.out.print(cipher[z]);
System.out.println();
//복호화
System.out.print("==================복호화과정=======================");
System.out.println();
System.out.print("암호문 : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.print("IP : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
cipher = Des.Ip(cipher);
for(j=15;j>=0;j--) {
System.out.print((j+1)+" 라운드(복호화) ");
System.out.println();
cipher = Des.Encrypt(cipher,keylist[j]);
System.out.print((j+1)+"번째 왼쪽32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.print((j+1)+"번째 오른쪽 32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z+32]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
}
cipher = Des.change(cipher);
cipher = Des.Ip2(cipher);
}//end of main
}//end of program
위 C1의 복호문은 Iloveyou
아래는 16진수 암호문 2564d997fbaa77e6에 대한 복호문(평문)의 출력입니다.
입력 ==> 암호문 C = 2564d997fbaa77e6(16 자리)
비밀 ==> 비밀키 K = kim12345(맨 뒤 빈자리 포함하여 8 자리)
출력 ==> 복호문 M = Iloveyou(맨 뒤 빈자리 포함하여 8 자리)
class Test_changhee {
public static void main(String arg[]) {
byte[] cipher = {
0,0,1,1,0,0,1,1,
0,0,1,1,0,1,0,1,
0,1,1,1,1,1,1,0,
1,1,1,1,0,0,0,1,
0,1,0,0,1,0,0,1,
1,1,0,0,1,1,0,0,
1,0,1,0,0,1,0,1,
1,1,1,0,1,0,0,1
};
byte[] key = {
1,0,1,1,1,1,0,0,
1,0,0,1,1,1,1,1,
1,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,1,
0,0,1,1,1,1,0,1,
1,0,1,1,1,0,1,0,
1,0,0,1,1,0,1,1,
0,0,1,0,0,1,0,0
};
byte[] key1 = new byte[64];
byte[][] keylist = new byte[16][48];
int i,j;
//키생성
System.out.print("---------------키생성과정---------------");
System.out.println();
System.out.print("원래의 키값 : ");
for(int z=0;z<64;z++) {
System.out.print(key[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
key1 = DesMakey.Pc1(key);
keylist = DesMakey.makey(key1);
//암호화
System.out.print("============암호화과정============");
System.out.println();
System.out.print("원래의 평문 : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
cipher = Des.Ip(cipher); //IP 순열
System.out.print("IP순열 통과후 : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
for(j=0;j<16;j++) { //16라운드 시작
System.out.print((j+1)+"라운드과정(암호화) ");
System.out.println();
cipher = Des.Encrypt(cipher,keylist[j]);
System.out.print((j+1)+"번째 왼쪽 32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.print((j+1)+"번째 오른쪽 32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z+32]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
}
cipher = Des.change(cipher); //최종 스위치
cipher = Des.Ip2(cipher); //역 IP 순열
System.out.print("암호문 : "); //최종 암호문출력
for(int z=0;z<64;z++)
System.out.print(cipher[z]);
System.out.println();
//복호화
System.out.print("==================복호화과정=======================");
System.out.println();
System.out.print("암호문 : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.print("IP : ");
for(int z=0;z<64;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
cipher = Des.Ip(cipher);
for(j=15;j>=0;j--) {
System.out.print((j+1)+" 라운드(복호화) ");
System.out.println();
cipher = Des.Encrypt(cipher,keylist[j]);
System.out.print((j+1)+"번째 왼쪽32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.print((j+1)+"번째 오른쪽 32비트 : ");
for(int z=0;z<32;z++) {
System.out.print(cipher[z+32]);
if(z%8==7)
System.out.print(" ");
}
System.out.println();
System.out.println();
}
cipher = Des.change(cipher);
cipher = Des.Ip2(cipher);
}//end of main
}//end of program
소개글