六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 187|回复: 0

加密器

[复制链接]

升级  60%

6

主题

6

主题

6

主题

童生

Rank: 1

积分
30
 楼主| 发表于 2013-2-5 02:18:04 | 显示全部楼层 |阅读模式
加密器

在/usr/local下创建encrypt.py
设置key1和key2,两个随机数。
sudo chmod 4755 encrypt.py
sudo ln -s encrypt.py encrypt

usage:encrypt 123456  

#!/usr/bin/python#filename=encrypt.pyimport gtkimport sysclass encode():  key1 = intKey1  key2 = intKey2  def ascii_list(self, s):    """return a list of ascii values of the characters in string s"""    return [ord(c) for c in s]  def byte_list(self, c):    """return a list of bytes values of the"""    return [chr(s) for s in c]  def encrypt(self, strContent_param):    listBytes = self.ascii_list(strContent_param)    i = 0    for byte in listBytes:      if ((byte > 47) and (byte < 58)):        listBytes = byte - 48      elif ((byte > 64) and (byte < 91)):        listBytes = byte - 55      elif ((byte > 96) and (byte < 123)):        listBytes = byte - 61      else:        break      listBytes = (self.key1 + i * self.key2) % 62 + listBytes      if (listBytes > 61):        listBytes = listBytes - 62      if ((listBytes >= 0) and (listBytes < 10)):        listBytes = listBytes + 48      elif ((listBytes > 9) and (listBytes < 36)):        listBytes = listBytes + 55      elif ((listBytes > 35) and (listBytes < 62)):        listBytes = listBytes + 61      else:        break      i = i + 1    listChar = self.byte_list(listBytes)    return ''.join(listChar)def main(args):  en = encode()  encryption = en.encrypt(args[1])  print encryption  cb = gtk.clipboard_get()  cb.set_text(encryption)  cb.store()if __name__ == "__main__":  main(sys.argv)

如此复制到clipboard的方式,对于terminal下使用shift+insert组合键无效,只能使用鼠标右键再点击“粘贴”。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表