你好,我自己设计了一个小小的加密器玩。你可以参考一下。这是带有界面的。
其中的算法你可以改掉。我是用来把密码转化一下并且复制到粘贴板来使用。希望对你有帮助!
import string
# -*- coding: utf-8 -*-
import wx
from time import *
from xlutils.copy import copy
import win32clipboard as w
import win32con
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title='encryption')
self.SetTopWindow(self.frame)
self.frame.register_close_callback(lambda: True)
self.frame.Show()
return True
class MyFrame(wx.Frame):
def __init__(self,parent,id=wx.ID_ANY, title="",
pos=(700,480),size=(180,100),
style=wx.DEFAULT_FRAME_STYLE ^wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX\
|wx.STAY_ON_TOP | wx.FRAME_TOOL_WINDOW |wx.SIMPLE_BORDER ,
name="MyFrame"):
bcolor=(0,0,0)
fcolor=(210,210,210)
super(MyFrame, self).__init__(parent, id, title,
pos, size, style,name)
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour(bcolor)
self.panel.SetForegroundColour(fcolor)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self.SetTransparent(251)
self.Bind(wx.EVT_CLOSE, self.onClose)
fontbutton = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.BOLD)
self.ValueLabel1 = wx.StaticText(self.panel,-1,"superstar: ", pos=(3,10))
self.ValueLabel1.SetFont(fontbutton)
self.Value1 = wx.TextCtrl(self.panel,-1,"",pos=(65,10),
size=(106,-1),style=wx.TE_PASSWORD)
self.Value1.SetBackgroundColour(bcolor)
self.Value1.SetForegroundColour(fcolor)
self.Value1.SetInsertionPoint(11)
self.Bind(wx.EVT_TEXT_ENTER,self.Value1Enter,self.Value1)
confirm=wx.Button(self.panel,label='Confirm',pos=(3,40),size=(82,-1),style=wx.BU_AUTODRAW)
confirm.SetFont(fontbutton)
confirm.SetBackgroundColour(bcolor)
confirm.SetForegroundColour(fcolor)
self.Bind(wx.EVT_BUTTON,self.confirmButton,confirm)
clear=wx.Button(self.panel,label='Clear',pos=(90,40),size=(82,-1),style=wx.BU_AUTODRAW)
clear.SetFont(fontbutton)
clear.SetBackgroundColour(bcolor)
clear.SetForegroundColour(fcolor)
self.Bind(wx.EVT_BUTTON,self.clearButton,clear)
def clearButton(self,event):
self.Value1.SetValue('')
w.OpenClipboard()
w.EmptyClipboard()
w.CloseClipboard()
def OnKeyDown(self,event):
keycode = event.GetKeyCode()
if keycode == wx.WXK_UP:
print 'yes'
def Value1Enter(self, event):
self.getvalue1=self.Value1.GetValue()
def confirmButton(self,event):
self.getvalue1=self.encrypt(self.Value1.GetValue())
self.copyToClip(self.getvalue1)
def copyToClip(self,data):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData(win32con.CF_TEXT, data)
w.CloseClipboard()
def register_close_callback(self, callback):
self.__close_callback = callback
def encrypt(self,s):
lis=''
ss=string.letters+string.digits
for i in xrange(len(s)):
pos=ss.find(s[i])
num=pos**(i%4+len(s))
lis+=ss[num/100%62]+ss[num%100%62]
return lis
def onClose(self, event):
self.Destroy()
w.OpenClipboard()
w.EmptyClipboard()
w.CloseClipboard()
if __name__ == '__main__':
app=MyApp(False)
app.MainLoop()