Python Forum
Vernam encryption method for files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vernam encryption method for files
#1
I have the following code snippet:

import secrets

def VernamCipherFunction(text, key):
      result = "";
      ptr = 0;
      for char in text:
            result = result + chr(ord(char) ^ ord(key[ptr]));
            ptr = ptr + 1;
            if ptr == len(key):
                  ptr = 0;
      return result

encryption_key="g2049ih259gh49uh4509uh409uh0e89ru09UEWHF938RUR0E19H1R309FUH109HR1309HGUU98H9ueghr9u4h09hr49h9grut4h209rhOVJEDFHFE8H9R3UHGH8H2UH2EH29HG9H9UP(UHU9uh8UhUHu89hzxuU89XXCU9csvhuifeqph9fqbeo3gr8uhf8uh8u8zxcg8UOH8D21H2E8HFE278HE837E782FH29H297H2F9H27187ey872f874873qrev8gr18gr87*&&^*&^T76gf8g8g871d38oG76g187gd2876gr377264gr8731g78fr31r89834gg82284ruhg8uh48uh8u284uh28hr28uh(*G(&YGy7gf1398r319r3g8ygr8e8y(&*G987e3gf978egry8g98YG7YFEGWR7Y91GREY7G19R87G2897gg6efw9re1g9e1g997FE3GR92R8EE298F7YG2E8G18HG8yf3r8gre2982r472gr2489rgh87h17(*YG(*G(&^&^9^&*&^&^f&^F&^f87F676f7YF&^%R&)(*&*&Y(*G&FG&TF^F^%R%R&%&^DR%^D%$D%D%$EXYFCKHGVKJHBI*YT&^76t76r65r65D^RD&^54d%$E^%43w43W5@Q#@a%$#s6%$ES%&s%&D&^d^%RE^%*TF&IF&F*^f*Go8GOYG&F%D$#S@A@A4gOUIULIBLIBO(G^F^%^%E&^$%E&"
otp = ''
for i in range(55):
     otp += secrets.choice(encryption_key)



 
while True:
    input_text = input("\nEnter File To Encrypt:\t");
    fh=open(input_text, "w")
    for encryption in fh:
        fh.writelines=encryption
        encryption=VernamCipherFunction(input_text, encryption_key)
    print("\nFile is encrypted");
    fh.close()
    break
exit
    
The program runs okay, but during runtime the whole file was truncated when users tried to input filename.

Any suggestions from any users will be appreciated.
Reply


Messages In This Thread
Vernam encryption method for files - by JohnCTX - Sep-18-2019, 12:09 PM
RE: Vernam encryption method for files - by JohnCTX - Sep-18-2019, 04:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,870 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  need help one time pad encryption implementation ! nad556 1 1,941 Nov-28-2020, 06:11 PM
Last Post: nad556
  encryption and decryption with python ibrahim 1 1,806 May-16-2020, 03:14 PM
Last Post: Larz60+
  File encryption itzik 5 2,853 Nov-05-2019, 12:29 PM
Last Post: Gribouillis
  Regarding encryption and decryption naressh1994 1 2,428 Jan-25-2019, 07:26 AM
Last Post: buran
  AES encryption - does not match between arduino and python 3 crypto guillaume55 0 4,020 Sep-23-2018, 11:14 AM
Last Post: guillaume55
  Python function that uses a word as the encryption key, rather than an integer wak_stephanie 4 4,826 Aug-31-2018, 12:16 PM
Last Post: perfringo
  lab experiment / encryption pythan 0 2,458 Jun-09-2018, 07:19 PM
Last Post: pythan
  Errors in my encryption algorithm SlimeBOOS 1 2,578 Dec-16-2017, 06:23 PM
Last Post: SlimeBOOS
  Attempting to port XTea Encryption from C to Python sonic1015 1 3,297 Jun-06-2017, 07:12 PM
Last Post: sonic1015

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020