@@ -10,17 +10,71 @@ public class RepeatingkeyVigenere : ICryptographicTechnique<string, string>
10
10
{
11
11
public string Analyse ( string plainText , string cipherText )
12
12
{
13
- throw new NotImplementedException ( ) ;
13
+ cipherText = cipherText . ToLower ( ) ;
14
+ int clength = cipherText . Length ;
15
+ string alphabet = "abcdefghijklmnopqrstuvwxyz" ;
16
+ string key = "" ;
17
+ string temp = "" ;
18
+ for ( int i = 0 ; i < clength ; i ++ )
19
+ {
20
+ key = key + alphabet [ ( ( alphabet . IndexOf ( cipherText [ i ] ) - alphabet . IndexOf ( plainText [ i ] ) ) + 26 ) % 26 ] ;
21
+ }
22
+ temp = temp + key [ 0 ] ;
23
+ int klength = key . Length ;
24
+ for ( int i = 1 ; i < klength ; i ++ )
25
+ {
26
+ if ( cipherText . Equals ( Encrypt ( plainText , temp ) ) )
27
+ {
28
+ return temp ;
29
+ }
30
+ temp = temp + key [ i ] ;
31
+ }
32
+ return key ;
33
+ //throw new NotImplementedException();
14
34
}
15
35
16
36
public string Decrypt ( string cipherText , string key )
17
37
{
18
- throw new NotImplementedException ( ) ;
38
+ cipherText = cipherText . ToLower ( ) ;
39
+ int clength = cipherText . Length ;
40
+ string plaintext = "" ;
41
+ string alphabet = "abcdefghijklmnopqrstuvwxyz" ;
42
+ int temp = 0 ;
43
+ while ( key . Length != clength )
44
+ {
45
+ key += key [ temp ] ;
46
+ temp ++ ;
47
+ }
48
+ for ( int i = 0 ; i < clength ; i ++ )
49
+ {
50
+ plaintext = plaintext + alphabet [ ( ( alphabet . IndexOf ( cipherText [ i ] ) - alphabet . IndexOf ( key [ i ] ) ) + 26 ) % 26 ] ;
51
+
52
+ }
53
+
54
+ return plaintext ;
55
+ //throw new NotImplementedException();
56
+
19
57
}
20
58
59
+
21
60
public string Encrypt ( string plainText , string key )
22
61
{
23
- throw new NotImplementedException ( ) ;
62
+ int temp = 0 ;
63
+ int plength = plainText . Length ;
64
+ string ciphertext = "" ;
65
+ string alphabet = "abcdefghijklmnopqrstuvwxyz" ;
66
+ while ( key . Length != plainText . Length )
67
+ {
68
+ key = key + key [ temp ] ;
69
+ temp ++ ;
70
+ }
71
+ for ( int i = 0 ; i < plength ; i ++ )
72
+ {
73
+ ciphertext = ciphertext + alphabet [ ( ( alphabet . IndexOf ( plainText [ i ] ) + alphabet . IndexOf ( key [ i ] ) ) ) % 26 ] ;
74
+
75
+ }
76
+ return ciphertext ;
77
+ //throw new NotImplementedException();
24
78
}
25
79
}
26
80
}
0 commit comments