diff --git a/edcode.py b/edcode.py index 845dd17..ae9592b 100644 --- a/edcode.py +++ b/edcode.py @@ -5,15 +5,12 @@ import json import base64 import hashlib -import multiprocessing.pool from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex -from pyDes import des, PAD_PKCS5, ECB, CBC +from pyDes import des, PAD_PKCS5, CBC import binascii import urllib.parse as up - - def decodes(decode,value): decode_dict = \ { @@ -37,27 +34,11 @@ def decodes(decode,value): else: print('暂不支持此解密') exit(0) - if(number == 1): - value = decsha(value,dectype='md5') - return value - elif(number == 2): - value = decsha(value,dectype='md4') - return value - elif(number == 3): - value = decsha(value,dectype='sha512') - return value - elif(number == 4): - value = decsha(value,dectype='sha1') - return value - elif(number == 5): - value = decsha(value,dectype='sha384') - return value - elif(number == 6): - value = decsha(value,dectype='sha224') - return value - elif(number == 7): - value = decsha(value,dectype='sha256') - return value + if(number < 8): + for number in range(1,8): + dectype = decode.lower() + value = decsha(value,dectype) + return value elif(number == 8): value = decbase64(value) return value @@ -71,9 +52,6 @@ def decodes(decode,value): value = decurl(value) return value - - - def decsha(value,dectype): print(dectype) for i in range(1,int(9e10)): @@ -85,7 +63,6 @@ def decsha(value,dectype): print('无匹配') exit(0) - def decbase64(value): value = value.encode(encoding='utf-8') try: @@ -95,7 +72,6 @@ def decbase64(value): print('格式错误') exit(0) - def decaes(value): key = input('请输入key: ') iv = input('请输入偏移值: ') @@ -109,7 +85,6 @@ def decaes(value): print('密钥或者偏移错误') exit(0) - def decdes(value): key = input('请输入key: ') iv = input('请输入偏移: ') @@ -120,12 +95,10 @@ def decdes(value): except ValueError: print('密钥或者偏移错误') exit(0) - def decurl(value): value = up.unquote(value) return value - def encodes(enable,value): enable_dict = \ { @@ -136,13 +109,13 @@ def encodes(enable,value): 'SHA224': 5, 'sha224': 5, 'SHA256': 6, 'sha256': 6, 'SHA384': 7, 'sha384': 7, - 'BASE64': 8, 'base64': 8, + 'SHA3-512': 8, 'sha3-512': 8, 'BLAKE2B': 9, 'blake2b': 9, 'BLAKE2S': 10, 'blake2s': 10, 'SHA3-224': 11, 'sha3-224': 11, 'SHA3-256': 12, 'sha3-256': 12, 'SHA3-384': 13, 'sha3-384': 13, - 'SHA3-512': 14, 'sha3-512': 14, + 'BASE64': 14, 'base64': 14, 'SHAKE-128': 15, 'shake-128': 15, 'SHAKE-256': 16, 'shake-256': 16, 'AES': 17, 'aes': 17, @@ -158,93 +131,36 @@ def encodes(enable,value): number = enable_dict[i] else: return 'NO' - - if(number == 1): - value = encmisc(enable,value) - return value - - if(number == 2): - value = encmisc(enable,value) - return value - - if(number == 3): - value = encmisc(enable,value) - return value - - if(number == 4): - value = encmisc(enable,value) - return value - - if(number == 5): - value = encmisc(enable,value) - return value - - if(number == 6): - value = encmisc(enable,value) - return value - - if(number == 7): - value = encmisc(enable,value) - return value - - if(number == 8): - value = base64.b64encode(value) - return value - - if(number == 9): - value = encmisc(enable,value) - return value - - if(number == 10): - value = encmisc(enable,value) - return value - - if(number == 11): - value = encmisc(enable,value) - return value - - if(number == 12): - value = encmisc(enable,value) - return value - - if(number == 13): - value = encmisc(enable,value) - return value - - if(number == 14): - value = encmisc(enable,value) - return value + if(number < 15): + for number in range(1,15): + value = encmisc(enable,value) + return value if(number == 15): length = int(input('请输入长度(Bits): ')) length /= 8 value = hashlib.shake_128(str(value).encode(encoding='utf-8')).hexdigest(int(length)) return value - - if(number == 16): + elif(number == 16): length = int(input('请输入长度(Bits): ')) length /= 8 value = hashlib.shake_256(str(value).encode(encoding='utf-8')).hexdigest(int(length)) return value - - if(number == 17): + elif(number == 17): value = str(encaes(value)) return value - - if(number == 18): + elif(number == 18): value = encdes(value) return value - if(number == 19): + elif(number == 19): value = enchmac(value) return value - if(number == 20): + elif(number == 20): value = encurl(value) return value - def encmisc(enctype,value): value = hashlib.new(enctype,str(value).encode(encoding='utf-8')).hexdigest() return value - def encaes(value): key = input('请输入key: ').encode(encoding='utf-8') iv = input('请输入偏移: ').encode() @@ -275,11 +191,10 @@ def encdes(value): except ValueError: print('偏移量 或者 key 错误') exit(0) - def enchmac(value): key = input('请输入key: ') hashtype = input('请输入加密类型\n sha1 , sha224 , sha256 , sha384 , sha512 , md5 \n默认 MD5: ') - if(hashtype == ''): + if(hashtype == '') or (hashtype == 'md5'): value = hmac.new(key.encode(encoding='utf-8'),value.encode(encoding='utf-8'),hashlib.md5) elif(hashtype == 'sha1') or (hashtype == 'SHA1'): value = hmac.new(key.encode(encoding='utf-8'), value.encode(encoding='utf-8'), hashlib.sha1) @@ -576,7 +491,10 @@ def main(): print('加密成功:' + str(encode)) elif(interface == 2): local_status = encodes(encode, value) - print('加密成功:' + str(local_status)) + if(local_status != 'NO'): + print('加密成功:' + str(local_status)) + else: + print('不支持此加密方式') elif(interface == 3): local_status = encodes(encode,value) if(local_status != 'NO'): @@ -591,4 +509,4 @@ def main(): print('不支持此加密方式') if __name__ == '__main__': - main() \ No newline at end of file + main()