0

I'm very confused by our task : "Develop the part of the program that generates an eight key character key the program will use to encrypt the message". We are trying to create an encryption program. The code I have so far:

Files

def fileopen():
  filename=input('What is the name of the file: ')

  with open(filename) as yarr:
        contents=yarr.read()
        return contents

Menu

print ("Hello, welcome to the encryption/decryption program")
print ("1 - Encryption")
print ("2 - Decryption")
print ("3 - Exit")
choice=input ("Enter a Number")
while True:
  if choice=="1":
        print("Encryption Selected")
        filecontents=fileopen()
        print(filecontents)
        break

  elif choice=="2":
        print("Decryption Selected")
        break

  elif choice=="3":
        print("Thank you, come again")
        break

  else:
        choice=input("Incorrect number")
        continue
Filburt
  • 17,626
  • 12
  • 64
  • 115
Callumbowyer
  • 1
  • 1
  • 1
  • I'm confused too. What is an "eight key character key"? Did you perhaps mean "eight character key" (i.e., a random string of eight characters)? – r3mainer Nov 16 '16 at 13:05

2 Answers2

0

try using a Caesar cipher.

This is my source for it:

Caesar Cipher

MAX_KEY_SIZE = 26

def getMode():
    while True:
        print('Do you wish to encrypt or decrypt or brute force a message?')
        mode = input().lower()
        if mode in 'encrypt e decrypt d brute b'.split():
            return mode
        else:
            print('Enter either "encrypt" or "e" or "decrypt" or "d" or "brute" or "b".')

def getMessage():
    print('Enter your message:')
    return input()

def getKey():
    key = 0
    while True:
        print('Enter the key number (1-%s)' % (MAX_KEY_SIZE))
        key = int(input())
        if (key >= 1 and key <= MAX_KEY_SIZE):
            return key

def getTranslatedMessage(mode, message, key):
    if mode[0] == 'd':
        key = -key
    translated = ''

    for symbol in message:
        if symbol.isalpha():
            num = ord(symbol)
            num += key

            if symbol.isupper():
                if num > ord('Z'):
                    num -= 26
                elif num < ord('A'):
                    num += 26
            elif symbol.islower():
                if num > ord('z'):
                    num -= 26
                elif num < ord('a'):
                    num += 26

            translated += chr(num)
        else:
            translated += symbol
    return translated

mode = getMode()
message = getMessage()
if mode[0] != 'b':
    key = getKey()
print ('Your translated text is:')
if mode[0] != 'b':
    print(getTranslatedMessage(mode,message,key))
else:
    for key in range(1, MAX_KEY_SIZE + 1):
        print(key,getTranslatedMessage('decrypt',message,key))
key = getKey()

print('Your translated text is:')
print(getTranslatedMessage(mode, message, key))

Works like this:

First define if you want to decrypt or encrypt text (write e or d and press enter). Next enter your message and confirm with enter. Next input a number and remember it for when you want to decrypt the message. Then hit enter and you get your encrypted/decrypted message.

You can just rename the questions and add a input field in an if statement so that it also converts text file.

Hope this helps :)

Jousi
  • 456
  • 4
  • 26
0

You can generate a randon string using the example in the following Random string generation with upper case letters and digits in Python and there is a simple encryption method here Simple way to encode a string according to a password?. Hope this helps

Community
  • 1
  • 1
Lee
  • 63
  • 1
  • 6