wasSharp – Diff between revs 1 and 5

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 1 Rev 5
Line 23... Line 23...
23 /// <param name="message">the message to encyrpt or decrypt</param> 23 /// <param name="message">the message to encyrpt or decrypt</param>
24 /// <param name="rotors">any combination of: 1, 2, 3, 4, 5, 6, 7, 8, b, g</param> 24 /// <param name="rotors">any combination of: 1, 2, 3, 4, 5, 6, 7, 8, b, g</param>
25 /// <param name="plugs">the letter representing the start character for the rotor</param> 25 /// <param name="plugs">the letter representing the start character for the rotor</param>
26 /// <param name="reflector">any one of: B, b, C, c</param> 26 /// <param name="reflector">any one of: B, b, C, c</param>
27 /// <returns>either a decrypted or encrypted string</returns> 27 /// <returns>either a decrypted or encrypted string</returns>
28 public static string wasEnigma(string message, char[] rotors, char[] plugs, char reflector) 28 public static string ENIGMA(string message, char[] rotors, char[] plugs, char reflector)
29 { 29 {
30 Dictionary<char, char[]> def_rotors = new Dictionary<char, char[]> 30 Dictionary<char, char[]> def_rotors = new Dictionary<char, char[]>
31 { 31 {
32 { 32 {
33 '1', new[] 33 '1', new[]
Line 185... Line 185...
185 foreach (char rotor in rotors) 185 foreach (char rotor in rotors)
186 { 186 {
187 char plug = plugs[Array.IndexOf(rotors, rotor)]; 187 char plug = plugs[Array.IndexOf(rotors, rotor)];
188 int i = Array.IndexOf(def_rotors[rotor], plug); 188 int i = Array.IndexOf(def_rotors[rotor], plug);
189 if (i.Equals(0)) continue; 189 if (i.Equals(0)) continue;
190 def_rotors[rotor] = Arrays.wasConcatenateArrays(new[] {plug}, 190 def_rotors[rotor] = Arrays.ConcatenateArrays(new[] {plug},
191 Arrays.wasGetSubArray(Arrays.wasDeleteSubArray(def_rotors[rotor], i, i), i, -1), 191 Arrays.GetSubArray(Arrays.DeleteSubArray(def_rotors[rotor], i, i), i, -1),
192 Arrays.wasGetSubArray(Arrays.wasDeleteSubArray(def_rotors[rotor], i + 1, -1), 0, i - 1)); 192 Arrays.GetSubArray(Arrays.DeleteSubArray(def_rotors[rotor], i + 1, -1), 0, i - 1));
193 } 193 }
Line 194... Line 194...
194   194  
195 StringBuilder result = new StringBuilder(); 195 StringBuilder result = new StringBuilder();
196 foreach (char c in message) 196 foreach (char c in message)
Line 207... Line 207...
207 Action<char[]> rotate = o => 207 Action<char[]> rotate = o =>
208 { 208 {
209 int i = o.Length - 1; 209 int i = o.Length - 1;
210 do 210 do
211 { 211 {
212 def_rotors[o[0]] = Arrays.wasForwardPermuteArrayElements(def_rotors[o[0]], 1); 212 def_rotors[o[0]] = Arrays.ForwardPermuteArrayElements(def_rotors[o[0]], 1);
213 if (i.Equals(0)) 213 if (i.Equals(0))
214 { 214 {
215 rotors = Arrays.wasReversePermuteArrayElements(o, 1); 215 rotors = Arrays.ReversePermuteArrayElements(o, 1);
216 continue; 216 continue;
217 } 217 }
218 l = Arrays.wasGetElementAt(def_rotors[o[1]], Array.IndexOf(def_rotors[o[0]], l) - 1); 218 l = Arrays.GetElementAt(def_rotors[o[1]], Array.IndexOf(def_rotors[o[0]], l) - 1);
219 o = Arrays.wasReversePermuteArrayElements(o, 1); 219 o = Arrays.ReversePermuteArrayElements(o, 1);
220 } while (--i > -1); 220 } while (--i > -1);
221 }; 221 };
Line 222... Line 222...
222   222  
223 // Forward pass through the Enigma's rotors. 223 // Forward pass through the Enigma's rotors.
Line 250... Line 250...
250 /// Expand the VIGENRE key to the length of the input. 250 /// Expand the VIGENRE key to the length of the input.
251 /// </summary> 251 /// </summary>
252 /// <param name="input">the input to expand to</param> 252 /// <param name="input">the input to expand to</param>
253 /// <param name="enc_key">the key to expand</param> 253 /// <param name="enc_key">the key to expand</param>
254 /// <returns>the expanded key</returns> 254 /// <returns>the expanded key</returns>
255 public static string wasVigenereExpandKey(string input, string enc_key) 255 public static string VIGENEREExpandKey(string input, string enc_key)
256 { 256 {
257 string exp_key = string.Empty; 257 string exp_key = string.Empty;
258 int i = 0, j = 0; 258 int i = 0, j = 0;
259 do 259 do
260 { 260 {
Line 280... Line 280...
280 /// Encrypt using VIGENERE. 280 /// Encrypt using VIGENERE.
281 /// </summary> 281 /// </summary>
282 /// <param name="input">the input to encrypt</param> 282 /// <param name="input">the input to encrypt</param>
283 /// <param name="enc_key">the key to encrypt with</param> 283 /// <param name="enc_key">the key to encrypt with</param>
284 /// <returns>the encrypted input</returns> 284 /// <returns>the encrypted input</returns>
285 public static string wasEncryptVIGENERE(string input, string enc_key) 285 public static string EncryptVIGENERE(string input, string enc_key)
286 { 286 {
287 char[] a = 287 char[] a =
288 { 288 {
289 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 289 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
290 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' 290 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
291 }; 291 };
Line 292... Line 292...
292   292  
293 enc_key = wasVigenereExpandKey(input, enc_key); 293 enc_key = VIGENEREExpandKey(input, enc_key);
294 string result = string.Empty; 294 string result = string.Empty;
295 int i = 0; 295 int i = 0;
296 do 296 do
297 { 297 {
Line 301... Line 301...
301 result += p; 301 result += p;
302 ++i; 302 ++i;
303 continue; 303 continue;
304 } 304 }
305 char q = 305 char q =
306 Arrays.wasReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i]))[ 306 Arrays.ReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i]))[
307 Array.IndexOf(a, char.ToLowerInvariant(p))]; 307 Array.IndexOf(a, char.ToLowerInvariant(p))];
308 if (char.IsUpper(p)) 308 if (char.IsUpper(p))
309 { 309 {
310 q = char.ToUpperInvariant(q); 310 q = char.ToUpperInvariant(q);
311 } 311 }
Line 322... Line 322...
322 /// Decrypt using VIGENERE. 322 /// Decrypt using VIGENERE.
323 /// </summary> 323 /// </summary>
324 /// <param name="input">the input to decrypt</param> 324 /// <param name="input">the input to decrypt</param>
325 /// <param name="enc_key">the key to decrypt with</param> 325 /// <param name="enc_key">the key to decrypt with</param>
326 /// <returns>the decrypted input</returns> 326 /// <returns>the decrypted input</returns>
327 public static string wasDecryptVIGENERE(string input, string enc_key) 327 public static string DecryptVIGENERE(string input, string enc_key)
328 { 328 {
329 char[] a = 329 char[] a =
330 { 330 {
331 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 331 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
332 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' 332 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
333 }; 333 };
Line 334... Line 334...
334   334  
335 enc_key = wasVigenereExpandKey(input, enc_key); 335 enc_key = VIGENEREExpandKey(input, enc_key);
336 string result = string.Empty; 336 string result = string.Empty;
337 int i = 0; 337 int i = 0;
338 do 338 do
339 { 339 {
Line 344... Line 344...
344 ++i; 344 ++i;
345 continue; 345 continue;
346 } 346 }
347 char q = 347 char q =
348 a[ 348 a[
349 Array.IndexOf(Arrays.wasReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i])), 349 Array.IndexOf(Arrays.ReversePermuteArrayElements(a, Array.IndexOf(a, enc_key[i])),
350 char.ToLowerInvariant(p))]; 350 char.ToLowerInvariant(p))];
351 if (char.IsUpper(p)) 351 if (char.IsUpper(p))
352 { 352 {
353 q = char.ToUpperInvariant(q); 353 q = char.ToUpperInvariant(q);
354 } 354 }
Line 364... Line 364...
364 /// <summary> 364 /// <summary>
365 /// An implementation of the ATBASH cypher for latin alphabets. 365 /// An implementation of the ATBASH cypher for latin alphabets.
366 /// </summary> 366 /// </summary>
367 /// <param name="data">the data to encrypt or decrypt</param> 367 /// <param name="data">the data to encrypt or decrypt</param>
368 /// <returns>the encrypted or decrypted data</returns> 368 /// <returns>the encrypted or decrypted data</returns>
369 public static string wasATBASH(string data) 369 public static string ATBASH(string data)
370 { 370 {
371 char[] a = 371 char[] a =
372 { 372 {
373 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 373 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
374 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' 374 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'