Samia Souror

Samia Souror

  • NA
  • 33
  • 4.8k

What is the problem of increasing time encryption Algorithm?

Feb 21 2019 4:02 PM
I have my own stream cipher algorithm, and I made a comparison between it and AES performance. I tested it on several files with different sizes(to 500KB). Its encryption/decryption time is less than AES for files about 500KB. but with files more than 500KB, its encryption time is more than AES but still its decryption time is the least one.
  1. public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)  
  2. {  
  3. byte[] encryptedBytes = null;  
  4. byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };  
  5. using (MemoryStream ms = new MemoryStream())  
  6. {  
  7. using (RijndaelManaged AES = new RijndaelManaged()) {  
  8. AES.KeySize = 128;  
  9. AES.BlockSize = 128;  
  10. var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);  
  11. AES.Key = key.GetBytes(AES.KeySize / 8);  
  12. AES.IV = key.GetBytes(AES.BlockSize / 8);  
  13. AES.Padding = PaddingMode.Zeros;  
  14. AES.Mode = CipherMode.CFB;  
  15. using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))  
  16. { cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);  
  17. cs.Close();  
  18. } encryptedBytes = ms.ToArray();  
  19. }  
  20. ms.Close();  
  21. }  
  22. return encryptedBytes;  
  23. }  
  24. public static byte[] AES_Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)  
  25. byte[] decryptedBytes = null;  
  26. byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };  
  27. using (MemoryStream ms = new MemoryStream())  
  28. using (RijndaelManaged AES = new RijndaelManaged())  
  29. { AES.KeySize = 128;  
  30. AES.BlockSize = 128;  
  31. var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);  
  32. AES.Key = key.GetBytes(AES.KeySize / 8);  
  33. AES.IV = key.GetBytes(AES.BlockSize / 8);  
  34. AES.Padding = PaddingMode.Zeros;  
  35. AES.Mode = CipherMode.CFB;  
  36. using (var cs = new CryptoStream(ms,AES.CreateDecryptor(), CryptoStreamMode.Write))  
  37. { cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);  
  38. cs.Close(); }  
  39. decryptedBytes = ms.ToArray();  
  40. } } return decryptedBytes; }  
  41. My encryption algorithm  
  42. public static byte[] Encrypt(byte[] PlainTextBytes, byte[] KeyHashBytes)  
  43. { StringBuilder Builder = new StringBuilder();  
  44. for (int i = 0; i < KeyHashBytes.Length; i++)  
  45. { Builder.Append(KeyHashBytes[i].ToString("x2")); }  
  46. String KeyHashString = Builder.ToString();  
  47. Byte[] LeftHash = Encoding.ASCII.GetBytes(KeyHashString.Substring(0, 16));  
  48. Byte[] RightHash = Encoding.ASCII.GetBytes(KeyHashString.Substring(16));  
  49. Byte[] MappingData = new Byte[PlainTextBytes.Length];  
  50. Byte[] EncryptedBytes = new Byte[PlainTextBytes.Length * 2];  
  51. for (int i = 0; i < PlainTextBytes.Length; i++)  
  52. int PlainInteger = Convert.ToInt32(PlainTextBytes[i]);  
  53. bool Left = (PlainInteger % 2 == 0);  
  54. int MappingIndex = (PlainInteger % 16);  
  55. PlainTextBytes[i] = (byte)((Left) ? (PlainTextBytes[i] ^ LeftHash[MappingIndex]) : (PlainTextBytes[i] ^ RightHash[MappingIndex]));  
  56. int PlainByteInteger = (int)PlainTextBytes[i];  
  57. PlainTextBytes[i] = (byte)(Math.Floor(((double) (PlainByteInteger) / 2)) + 33);  
  58. MappingData [i] = (byte)(MappingIndex + ((Left) ? 0 : 16));  
  59. MappingData [i] = (byte)((((PlainByteInteger) % 2 == 1)) ? ((int)MappingData [i]) + 32 : ((int)MappingData [i]) + 0);  
  60. MappingData [i] = (byte)(((int)MappingData [i]) + 33);  
  61. EncryptedBytes[i * 2] = PlainTextBytes[i];  
  62. EncryptedBytes[i * 2 + 1] = MappingData [i];  
  63. }  
  64. return EncryptedBytes;  
  65. }  
  66. private void Encrypt_Click(object sender, EventArgs e)  
  67. string password1 = textPassword.ToString();  
  68. string password2 = textVerifiedPassword.ToString();  
  69. if (password1 == password2 && fileName != null)  
  70. byte[] bytesToBeEncrypted = File.ReadAllBytes(fileName);  
  71. byte[] passwordBytes = Encoding.UTF8.GetBytes(password1);  
  72. byte[] PwdHash = MD5.Create().ComputeHash(passwordBytes);  
  73. byte[] bytesEncrypted = AES.AES_Encrypt(bytesToBeEncrypted, PwdHash);  
  74. byte[] bytesEncrypted = AES.AES_Decrypt(bytesToBeEncrypted, PwdHash);  
  75. byte[] bytesEncrypted = SCKSA.Encrypt(bytesToBeEncrypted, PwdHash);  
  76. byte[] bytesEncrypted = SCKSA.Decrypt(bytesToBeEncrypted, PwdHash); }}

Answers (1)