Skip to main content

RSA encryption arithmetic and be achieved by Python

The first approach of the algorithm, we random produce two prime numbers named p and q, Compute N = p * q note that N. Choose which should be less than N such that e and (p-1) (q-1) are relatively prime numbers. Public key is a pair of numbers (N, e). They should have no common factor other than 1. For example d is the decryption key, According to this algorithm (e*d) %( p-1) (q-1) = = = 1(identity sign), get d is the private key. Using the Euclidean algorithm to compute the modular inverse of e modulo N, the result is d. For example P is the ASCII code of a char in clear text. Then we take the RSA algorithm C = Pe % N. we can get C.

Why chose python. Because there is a problem for the other language, big number operation but python can it directly.

Main code: rsaEncrption.py

N = p * q # two big prime number p and q

d = 2 # d is the private key. it make the identic equation (e*d) % ((p-1)*(q-1)) === 1

while (e*d) %(p-1)*(q-1) != 1

d += 1

# public key : (N, e) private key : d

# cipherCode is a ASCII code of a char of cipherText

# plainCode is a ASCII Code of a char of clearText

cipherAsciiCode = (plainAsciiCode ** e) % N # encryption

plainAsciiCode = (cipherAsiccCode ** d) % N # decryption

Comments

Popular posts from this blog

手游开发资源(更新中)

开发平台: eclipse + eclipseME 地图编辑器: Tile Studio 教程: JavaDev.com SDK: WTK2.2 ; Nokia S60 , S40 ; Motorola SDK ; Forum: J2ME 权威网站+论坛 ; 老外的论坛 ; Archives and Links: 1) Resource List 2) BillDay.com 3) J2MEFAQ 4) J2ME Using Ant 5) another about j2me and ant 5) J2ME polish

设置 J2ME WTK的模拟器支持 SCREEN TOUCH

目前很多手机都支持触摸屏,最近版的WTK模拟器已经支持触摸屏事件响应,这样就可以DEBUG类似三星F480等触摸屏手机。 设置WTK模拟器为支持触摸屏的方法: 1) 找到WTK的安装目录,进入 \wtklib\devices\ 目录 2) 打开 DefaultColorPhone.properties 文件 3) 找到 "touch_screen=false" 改成 "touch_screen=true" 这样,DefaultColorPhone 模拟器就支持触摸屏相应了,类似的如果想改其他几个模拟器,修改相应的 *.properties 文件就可以。 测试: 打开模拟器,把鼠标放到模拟器的手机屏幕上,鼠标变成 "+", 表示设置成功。