import os
import hashlib
import random
import string
def function1():
try:
print(f.read())
except UnicodeDecodeError:
print('解码错误!')
print('')
f.close()
def function2():
I = open(s, 'r', encoding=x)
try:
print(I.read())
except UnicodeDecodeError:
print('解码错误!')
print('')
f.close()
def function3(x):
def generate_salt_hash(s: str):
salt = "".join([random.choice(string.ascii_lowercase) for i in range(4)])
s = s + salt
_md5 = hashlib.md5()
_md5.update(s.encode("utf-8"))
return salt + "$" + _md5.hexdigest()
password = x
p_md5_1 = generate_salt_hash(password)
print(p_md5_1)
with open('加密后的文件.txt', 'w') as file:
file.write(p_md5_1)
s = str(input('将文件托入或输入同文件夹的文件的文件名:'))
print('UTF-8格式:')
f = open(s, 'r', encoding='utf-8')
function1()
v1=str('utf-8')
print('ANSI格式:')
f = open(s, 'r', encoding='ANSI')
function1()
v2=str('ANSI')
print('UTF-16 LE格式:')
f = open(s, 'r', encoding='UTF-16 LE')
function1()
v3=str('UTF-16 LE')
print('UTF-16 BE格式:')
f = open(s, 'r', encoding='UTF-16 BE')
function1()
v4=str('UTF-16 BE')
print('UTF-32格式:')
f = open(s, 'r', encoding='UTF-32')
function1()
v5=str('UTF-32')
print('ASCII格式:')
f = open(s, 'r', encoding='ASCII')
function1()
v6=str('ASCII')
print('GBK格式:')
f = open(s, 'r', encoding='GBK')
function1()
v7=str('GBK')
print('GB2312格式:')
f = open(s, 'r', encoding='GB2312')
function1()
v8=str('GB2312')
print('GB18030格式:')
f = open(s, 'r', encoding='GB18030')
function1()
v9=str('GB18030')
print('ISO8859-1格式:')
f = open(s, 'r', encoding='ISO8859-1')
function1()
v10=str('ISO8859-1')
print('big5格式:')
f = open(s, 'r', encoding='big5')
function1()
v11=str('big5')
print('big5-HKSCS格式:')
f = open(s, 'r', encoding='big5-HKSCS')
function1()
v12=str('big5-HKSCS')