Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 837e380

Browse files
playfair added
1 parent 75cf1d5 commit 837e380

14 files changed

+15
-7
lines changed

‎SecurityLibrary/MainAlgorithms/PlayFair.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,30 @@ public string Decrypt(string cipherText, string key)
126126
}
127127
}
128128

129+
130+
string ans = PT;
129131
if (PT[PT.Length - 1] == 'x')
130132
{
131-
PT = PT.Remove(PT.Length - 1);
133+
ans = ans.Remove(PT.Length - 1);
132134
}
133135

134-
for (int i = 0; i < PT.Length; i++)
136+
int w = 0;
137+
for (int i = 0; i < ans.Length; i++)
135138
{
136139
if (PT[i] == 'x')
137140
{
138141
if (PT[i - 1] == PT[i + 1])
139142
{
140-
if (i+1<PT.Length && (i+1)%2==0)
143+
if (i+w<ans.Length && (i-1)%2==0)
141144
{
142-
PT = PT.Remove(i, 1);
145+
ans = ans.Remove(i+w, 1);
146+
w--;
143147
}
144148
}
145149
}
146150
}
147151

148-
FPT += PT;
152+
FPT += ans;
149153
}
150154

151155
Console.WriteLine(FPT);
@@ -156,13 +160,13 @@ public string Decrypt(string cipherText, string key)
156160
public string Encrypt(string plainText, string key)
157161
{
158162
string CT = "";
163+
159164
KOMatrices KOkey = KOFunc(ModifiedKey(key));
160165
for (int i = 0; i < plainText.Length - 1; i+=2)
161166
{
162167
if (plainText[i] == plainText[i + 1])
163168
{
164-
i++;
165-
plainText = plainText.Substring(0, i) + 'x' + plainText.Substring(i);
169+
plainText = plainText.Substring(0, i+1) + 'x' + plainText.Substring(i+1);
166170
}
167171

168172
}
@@ -188,6 +192,9 @@ public string Encrypt(string plainText, string key)
188192
}
189193
}
190194

195+
196+
Console.WriteLine(CT.ToUpper());
197+
Console.WriteLine("\n\n");
191198
return CT.ToUpper();
192199
}
193200

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

‎SecurityPackage.v12.suo

0 Bytes
Binary file not shown.

‎SecurityPackageTest/PlayfairTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public void PlayfairTestEnc4()
9191
{
9292
PlayFair algorithm = new PlayFair();
9393
string cipher = algorithm.Encrypt(largePlain, largeKey);
94+
Console.WriteLine(largeCipher);
9495
Assert.IsTrue(cipher.Equals(largeCipher, StringComparison.InvariantCultureIgnoreCase));
9596
}
9697

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /