我一直无法尝试让我的代码导出正确的加密文本。我的代码不是导出已经选择和加密的文本而是导出一个只包含' []'
的文件。如果我不熟悉Python,我将如何解决此问题?
以下完整代码:
def getMessage():
print("Enter the file name which you want to Encrypt\n")
userMessage = input("")
try:
filetoencrypt = open(userMessage,"r")
print (filetoencrypt)
except:
print("You have given a file which does not exist. please try again.\n")
time.sleep(1)
choice()
else:
print("File has been Successfully found.")
toencrypt = []
for line in filetoencrypt:
toencrypt.append(line.strip()) #
key = generatekey()
print ("Key has been generated:" + key)
offset = offset_factor(key)
encrypted = []
for line in toencrypt:
encryptedline = ""
for char in line:
key1, number, getMessage = generatekey(), 0, ""
offset_factor1 = math.floor(number / 8) - 32
if char == '':
encryptedline +=''
else:
encrypt_letter = ord(char) + (offset_factor1)
if encrypt_letter > 126:
encrypt_letter -= 94
getMessage += str(chr(encrypt_letter))
for line in range(1):
print("")
NewEncrypt = input("Would you like to make it more secure, enter Yes or No: ")
time.sleep(1)
if NewEncrypt.upper() == "YES":
getMessage = getMessage.replace(" ", "")
getMessage = ' '.join([getMessage[i:i+5] for i in range(0, len(getMessage), 5)])
elif NewEncrypt.upper == "NO":
getMessage = getMessage
else:
print("You entered an invalid option.")
exit()
open(input("Text encrypted successfully. \nWhat would you like to save the new "
"file as (include the extension): "), mode="w").write(getMessage)
print ("File saved.")
sys.exit()
特别是这部分代码:
import pandas as pd
df=pd.read_clipboard()
df
Col1 Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9
A A 0 4247 5684 2068 393 237 16286
A A 0 0 2366 4159 3155 696 341
A B 18198 0 1114 1871 5392 1954 755
A B 17829 0 2695 2366 3768 1289 445
A C 18352 0 3545 7508 5099 2071 1239
In [9]: import numpy as np
In [10]: np.round(df.groupby(['Col1', 'Col2']).agg(['mean', 'std']),4)
Out[10]:
Col3 Col4 Col5 Col6 \
mean std mean std mean std mean
Col1 Col2
A A 0.0 0.0000 2123.5 3003.0825 4025.0 2346.1803 3113.5
B 18013.5 260.9224 0.0 0.0000 1904.5 1117.9358 2118.5
C 18352.0 NaN 0.0 NaN 3545.0 NaN 7508.0
Col7 Col8 Col9
std mean std mean std mean std
Col1 Col2
A A 1478.5603 1774 1953.0289 466.5 324.562 8313.5 11274.8176
B 350.0179 4580 1148.3414 1621.5 470.226 600.0 219.2031
C NaN 5099 NaN 2071.0 NaN 1239.0 NaN
答案 0 :(得分:0)
选择1是“加密消息”
if userChoice == "1":
return userChoice
但它没有调用加密方法,实际上没有encrypt()
方法,只返回“1”。