【发布时间】:2014-02-03 03:32:05
【问题描述】:
我刚刚完成了对脚本的一些修改,我尝试在终端上使用 Python 执行它,但终端提示如下:
which: no xclip in (/usr/local/bin: /usr/bin: /bin: /usr/local/sbin: /usr/sbin:/sbin:/home/myUser/bin)
which: no xsel in (/usr/local/bin: /usr/bin: /bin: /usr/local/sbin: /usr/sbin:/sbin:/home/myUser/bin)
这是我正在尝试执行的以下脚本:
import random, sys, CipherEncryptionP
def main():
random.seed(42)
for i in range(20):
message = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'*random.randint(4,40)
message = list(message)
random.shuffle(message)
print('Test #%s: "%s..."' % (i+1, message[:50]))
for key in range(1,len(message)):
encrypted = CipherEncryptionP.encryptMessage(message,key)
print('Transposition cipher test passed. ')
if __name__=='__main__':
main()
最后,这是您从上面运行代码所需的 CipherEncryptionP 脚本。
import pyperclip
def main():
message = raw_input("Give me your message: ")
keyValue = int(raw_input("Give a numeric value: "))
ciphertext = encryptMessage(message,keyValue)
print(ciphertext + '|')
pyperclip.copy(ciphertext)
def encryptMessage(message,keyValue):
ciphertext=['']*keyValue
for column in range(keyValue):
pointer= column
while pointer < len(message):
ciphertext[column]+=message[pointer]
pointer+=keyValue
return ''.join(ciphertext)
if __name__== '__main_':
main()
我正在运行内核版本为 2.6.32-431.1.2.el6.x86_64 的 Scientific Linux 6.2,Python 版本为 2.6.6。您可以从以下页面下载 pyperclip:http://invpy.com/pyperclip.py。
第一个代码用于测试第二个代码,它是我从http://inventwithpython.com/hacking/chapter10.html下载的转置密码。
欢迎所有建议和修改:)
【问题讨论】:
-
您是否安装了
xclip和xsel? -
which xclip,which xsel。如果没有安装,请安装它们。 -
它抛出以下内容: /usr/bin/which: no xclip in /usr/local/sbin: /usr/local/bin:/sbin:/usr/sbin:/sbin:/home /myUser/bin