repl.it
@_Sniper_Turtle_/

Encryption Python

Python

No description

fork
loading
Files
  • main.py
  • userdata.txt
  • usermodule.py
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import string as abc
import random
from colorama import Fore, Back, Style
from replit import clear
clear()
error=False
ABC=list(abc.ascii_lowercase)
allowedSymbols=["~","!","@","#","$","%","^","&","*","(",")","-","_","=","+","[","{","]","}",";",":","|",",","<",".",">","/","?"," "]
allowedChars=[]
message=[]
for i in range(len(ABC)):
  allowedChars.insert(0,ABC[i])
for i in range(len(allowedSymbols)):
  allowedChars.insert(0,allowedSymbols[i])
def encrypt():
  inputText = input(Style.BRIGHT+Fore.GREEN+Back.BLACK+'What is the encryptable message? Note that all capitalized letters will become lowercase.\n\n>>>')
  inputText=inputText.lower()
  Key = input('What is the key you want to encrypt your message with? (type "NEW" to generate one)\n\n>>>')
  if Key.upper() == 'NEW':
    Key = ''.join([random.choice(abc.ascii_letters) for n in range(len(inputText))]) #generates random string to be used as key, 32 characters long
    print('\n',str(Key),'is your key')
  Key.replace(' ','')
  for i in range(len(inputText)):
    if inputText[i].lower() not in allowedChars:
      print('Error! Unallowed character '+str(inputText[i])+' in input text.')
      error=True
  if error==False:
    print('Your plaintext is clean. Encrypting.')
    message=inputText.translate(str.maketrans({'a':'0 ','b':'1 ','c':'2 ','d':'3 ','e':'4 ','f':'5 ','g':'6 ','h':'7 ','i':'8 ','j':'9 ','k':'10 ','l':'11 ','m':'12 ','n':'13 ','o':'14 ','p':'15 ','q':'16 ','r':'17 ','s':'18 ','t':'19 ','u':'20 ','v':'21 ','w':'22 ','x':'23 ','y':'24 ','z':'25 ',' ':'','A':'0 ','B':'1 ','C':'2 ','D':'3 ','E':'4 ','F':'5 ','G':'6 ','H':'7 ','I':'8 ','J':'9 ','K':'10 ','L':'11 ','M':'12 ','N':'13 ','O':'14 ','P':'15 ','Q':'16 ','R':'17 ','S':'18 ','T':'19 ','U':'20 ','V':'21 ','W':'22 ','X':'23 ','Y':'24 ','Z':'25 ',' ':''}))
    Key=Key.translate(str.maketrans({'a':'0 ','b':'1 ','c':'2 ','d':'3 ','e':'4 ','f':'5 ','g':'6 ','h':'7 ','i':'8 ','j':'9 ','k':'10 ','l':'11 ','m':'12 ','n':'13 ','o':'14 ','p':'15 ','q':'16 ','r':'17 ','s':'18 ','t':'19 ','u':'20 ','v':'21 ','w':'22 ','x':'23 ','y':'24 ','z':'25 ','A':'0 ','B':'1 ','C':'2 ','D':'3 ','E':'4 ','F':'5 ','G':'6 ','H':'7 ','I':'8 ','J':'9 ','K':'10 ','L':'11 ','M':'12 ','N':'13 ','O':'14 ','P':'15 ','Q':'16 ','R':'17 ','S':'18 ','T':'19 ','U':'20 ','V':'21 ','W':'22 ','X':'23 ','Y':'24 ','Z':'25 '}))
    message=message.rstrip()
    Key=Key.rstrip()
    print('message (in numbers):',str(message))
    print('key (in numbers):',str(Key))
    message2 = message.split(" ")
    for character in range(len(message2)):    
      Key2 = Key.split(" ")
      char=str(int(message2[character])+int(Key2[character]))
      f=open('userdata.txt','w+')
      f.write('\nKey: '+str(Key)+'\nMessage: '+message+'\nOutput: '+inputText+'\n')
      f.write('_'*len(inputText)*2)
      f.close()
      print(str(char))
def decrypt():
  #stuff
  print('This is UNFINISHED')
encrypt()
?