mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Simplify code by dropping support for legacy Python (#1143)
* Simplify code by dropping support for legacy Python * sort() --> sorted()
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
import sys, random, cryptomath_module as cryptoMath
|
||||
|
||||
SYMBOLS = r""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
def decrypt(message):
|
||||
"""
|
||||
>>> decrypt('TMDETUX PMDVU')
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
# Primality Testing with the Rabin-Miller Algorithm
|
||||
|
||||
import random
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
def dencrypt(s, n):
|
||||
out = ''
|
||||
for c in s:
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
import random, sys, os
|
||||
import rabin_miller as rabinMiller, cryptomath_module as cryptoMath
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
import math
|
||||
|
||||
def main():
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user