-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeygen.cpp
89 lines (65 loc) · 1.58 KB
/
keygen.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<iostream>
#include<string.h>
#include<stdio.h>
#include <bits/stdc++.h>
using namespace std;
static int i;
//To perform left shift operation
string left_shift( string s, int d)
{
reverse(s.begin(), s.begin()+d);
reverse(s.begin()+d, s.end());
reverse(s.begin(), s.end());
return s;
}
//For permutation of string
string permute(string inputval)
{
int p48[48] = {14,17,11,24,1,5,
3,28,15,6,21,10,
23,19,12,14,26,8,
16,7,27,20,13,2,
41,52,31,37,47,55,
30,40,51,45,33,48,
44,49,39,56,34,53,
46,42,50,36,29,32};
string out_p=" ";
for(int i=0; i<48;i++)
{
out_p+=inputval[p48[i]-1];
}
return out_p;
}
//To split key equally and perform left shift
string split_key(string key_value)
{
string left_ip, right_ip;
string total_ip;
for(i=1;i<=16;i++)
{
string lip = key_value.substr(0,28);
string rip = key_value.substr(28,56);
if(i==1||i==2||i==9|i==16)
{
left_ip= left_shift(lip,1);
right_ip= left_shift(rip,1);
}
else
{
left_ip= left_shift(lip,2);
right_ip= left_shift(rip,2);
}
/*cout<<"L"<<i<<"\t"<<left_ip<<endl;
cout<<"R"<<i<<"\t"<<right_ip<<endl;*/
key_value= left_ip+right_ip;
string final_key =permute(key_value);
cout<<endl<<"Key "<<i<<"\t"<<final_key<<endl;
}
}
int main()
{
cout<<"56 bit key seed value is: ";
string key_value= "11100001100110010101010111111010101011001100111100011110";
cout<<key_value<<endl;
split_key(key_value);
}