Python Forum
Vernam encryption method for files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vernam encryption method for files
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

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:
        encryption=VernamCipherFunction(input_text, encryption_key)
    print("\nFile is encrypted");

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.
Its purpose of the program is to prevent users from obfuscating any app developer's source code.
However, its only obstacle that's preventing me from successfully encrypting a selected file was not to
truncate it; it was supposed encrypt it instead using the file handling techniques using the
write lines method of the file writing object.

Possibly Related Threads…
Thread Author Replies Views Last Post
  encryption and decryption with python ibrahim 1 339 May-16-2020, 03:14 PM
Last Post: Larz60+
  File encryption itzik 5 481 Nov-05-2019, 12:29 PM
Last Post: Gribouillis
  Regarding encryption and decryption naressh1994 1 709 Jan-25-2019, 07:26 AM
Last Post: buran
  AES encryption - does not match between arduino and python 3 crypto guillaume55 0 1,921 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 1,784 Aug-31-2018, 12:16 PM
Last Post: perfringo
  lab experiment / encryption pythan 0 984 Jun-09-2018, 07:19 PM
Last Post: pythan
  Errors in my encryption algorithm SlimeBOOS 1 1,111 Dec-16-2017, 06:23 PM
Last Post: SlimeBOOS
  Attempting to port XTea Encryption from C to Python sonic1015 1 1,676 Jun-06-2017, 07:12 PM
Last Post: sonic1015
  Testing homemade encryption program in python LEJONKINGEN 1 1,774 Mar-04-2017, 04:09 AM
Last Post: wavic
  What is an Encryption And Decryption Lamon112 8 3,466 Jan-14-2017, 10:14 PM
Last Post: Kebap

Forum Jump:

User Panel Messages

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