Simplify code by dropping support for legacy Python (#1143)

* Simplify code by dropping support for legacy Python

* sort() --> sorted()
This commit is contained in:
Christian Clauss
2019-08-19 15:37:49 +02:00
committed by GitHub
parent 32aa7ff081
commit 47a9ea2b0b
145 changed files with 367 additions and 976 deletions

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
import sys, random, cryptomath_module as cryptoMath
SYMBOLS = r""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""

View File

@@ -1,23 +1,15 @@
try: # Python 2
raw_input
unichr
except NameError: # Python 3
raw_input = input
unichr = chr
def Atbash():
def atbash():
output=""
for i in raw_input("Enter the sentence to be encrypted ").strip():
for i in input("Enter the sentence to be encrypted ").strip():
extract = ord(i)
if 65 <= extract <= 90:
output += unichr(155-extract)
output += chr(155-extract)
elif 97 <= extract <= 122:
output += unichr(219-extract)
output += chr(219-extract)
else:
output+=i
output += i
print(output)
if __name__ == '__main__':
Atbash()
atbash()

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
def decrypt(message):
"""
>>> decrypt('TMDETUX PMDVU')

View File

@@ -1,5 +1,3 @@
from __future__ import print_function
import random
@@ -15,7 +13,7 @@ class Onepad:
cipher.append(c)
key.append(k)
return cipher, key
def decrypt(self, cipher, key):
'''Function to decrypt text using psedo-random numbers.'''
plain = []

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
# Primality Testing with the Rabin-Miller Algorithm
import random

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
def dencrypt(s, n):
out = ''
for c in s:

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
import sys, rsa_key_generator as rkg, os
DEFAULT_BLOCK_SIZE = 128
@@ -16,7 +15,7 @@ def main():
if mode == 'encrypt':
if not os.path.exists('rsa_pubkey.txt'):
rkg.makeKeyFiles('rsa', 1024)
message = input('\nEnter message: ')
pubKeyFilename = 'rsa_pubkey.txt'
print('Encrypting and writing to %s...' % (filename))

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
import random, sys, os
import rabin_miller as rabinMiller, cryptomath_module as cryptoMath

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
import sys, random
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -18,7 +17,7 @@ def main():
translated = decryptMessage(key, message)
print('\n%sion: \n%s' % (mode.title(), translated))
def checkValidKey(key):
keyList = list(key)
lettersList = list(LETTERS)
@@ -49,7 +48,7 @@ def translateMessage(key, message, mode):
if mode == 'decrypt':
charsA, charsB = charsB, charsA
for symbol in message:
if symbol.upper() in charsA:
symIndex = charsA.find(symbol.upper())

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
import math
def main():

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
import time, os, sys
import transposition_cipher as transCipher
@@ -16,7 +15,7 @@ def main():
response = input('> ')
if not response.lower().startswith('y'):
sys.exit()
startTime = time.time()
if mode.lower().startswith('e'):
with open(inputFile) as f:
@@ -29,9 +28,9 @@ def main():
with open(outputFile, 'w') as outputObj:
outputObj.write(translated)
totalTime = round(time.time() - startTime, 2)
print(('Done (', totalTime, 'seconds )'))
if __name__ == '__main__':
main()

View File

@@ -1,4 +1,3 @@
from __future__ import print_function
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def main():