资源简介
AES-FINAL.rar
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Tue Nov 21 16:05:52 2017
@author: oyjiy
@topic : AES_128
“““
import data
import s2 as mul
# print(data.sbox[1])
nb = 4 # number of the coloum of states
nr = 10 # number of rounds of ciphering
nk = 4 # length of the key (words)
def encry(input_byte key):
“““
1. subbyte
2. shift rows
3. mix coloums(except the last round)
4. add key for each round
5. turn state to 1-D array
“““
state = [[] for j in range(4)]
for r in range(4):
for c in range(nb):
state[r].append(input_byte[r+4*c])
key_schedule = key_expan(key)
state = addkey(state key_schedule)
for rnd in range(1nr):
# with mix coloums
state = SubByte(state)
state = shift_row(state)
state = mix_col(state)
state = addkey(statekey_schedulernd)
# The last : without mix coloums
state = SubByte(state)
state = shift_row(state)
state = addkey(state key_schedule rnd + 1)
output = [None for i in range(4 * nb)]
for r in range(4):
for c in range(nb):
output[r + 4 * c] = state[r][c]
return output
def decrypt(cipher key):
state = [[] for i in range(nb)]
for r in range(4):
for c in range(nb):
state[r].append(cipher[r + 4 * c])
key_schedule = key_expan(key)
state = addkey(state key_schedule nr)
rnd = nr - 1
while rnd >= 1:
state = shift_row(state inv=True)
state = SubByte(state inv=True)
state = addkey(state key_schedule rnd)
state = mix_col(state inv=True)
rnd = rnd - 1
state = shift_row(state inv=True)
state = SubByte(state inv=True)
state = addkey(state key_schedule rnd)
output = [None for i in range(4 * nb)]
for r in range(4):
for c in range(nb):
output[r + 4 * c] = state[r][c]
return output
def key_expan(key):
key_sym = [ord(sym) for sym in key]
# key padding to 128 bits
if len(key_sym) < 4 * nk:
for i in range(4 * nk - len(key_sym)):
key_sym.append(0x01)
# 4 bytes->1 coloum->1 key_schedule
# init key_scedule: 4 coloums 0~3
key_schedule = [[] for i in range(4)]
for r in range(4):
for c in range(nk):
key_schedule[r].append(key_sym[r + 4 * c])
# expand key_scedule: 4~43
for col in range(nk nb * (nr + 1)):
# if col is K4
if col % nk == 0:
# tmp = K4
tmp = [key_schedule[row][col-1] for row in range(1 4)]
tmp.append(key_schedule[0][col-1])
# byte substitution using sbox
for j in range(len(tmp)): # K4[0]=0xa4
sbox_row = tmp[j] // 0x10 # sbox_row = a 整除16
sbox_col = tmp[j] % 0x10
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10429 2017-12-27 14:10 2015301500011-欧阳彤-密码学课程设计\AES_128.py
文件 3642 2017-11-21 16:18 2015301500011-欧阳彤-密码学课程设计\data.py
文件 535 2017-12-27 14:48 2015301500011-欧阳彤-密码学课程设计\README.txt
文件 10573 2017-12-27 14:04 2015301500011-欧阳彤-密码学课程设计\s2.py
文件 4167 2017-12-19 14:42 2015301500011-欧阳彤-密码学课程设计\test.py
文件 16 2017-11-30 17:08 2015301500011-欧阳彤-密码学课程设计\zcon.txt
文件 474839 2017-12-27 14:45 2015301500011-欧阳彤-密码学课程设计\2015301500011-欧阳彤-密码学课程设计.docx
目录 0 2017-12-27 14:47 2015301500011-欧阳彤-密码学课程设计
文件 149076 2017-10-01 11:24 2015301500011-欧阳彤-密码学课程设计\测试例子\cat.jpg
文件 149076 2017-12-27 14:11 2015301500011-欧阳彤-密码学课程设计\测试例子\crypted_cat.jpg
文件 149076 2017-12-27 14:11 2015301500011-欧阳彤-密码学课程设计\测试例子\decrypted_crypted_cat.jpg
目录 0 2017-12-27 14:45 2015301500011-欧阳彤-密码学课程设计\测试例子
----------- --------- ---------- ----- ----
951429 12
- 上一篇:简易步进电机S加减速
- 下一篇:AC转DC电源的电路设计
相关资源
- 纯正商业级应用-微信小程序开发实战
- NatCorder1.5.unitypackage
- Vue.js源码全方位深入解析.txt
-
Exchange.xm
l -
ADSelfService.xm
l - 串口工具.rar
- 集成了spring插件的eclipse.txt
- 接口测试-第一天.pdf
- data_odometry_color.txt
- swoole.txt
- 64Mircosoftoffice2016.txt
- 各种贴片元件IC封装库.rar
- 网络工程师BENETY2课件.txt
- 网络工程师BENETS2课件.txt
- 网络工程师BENETS1课件.txt
- 4章有序统计类CFAR检测器.rar
- cassandra.txt
- 《Unity5.x从入门到精通》配套光盘资源
- 下落的小鸟终结修改版.rar
- wchzym_7185131.zip
- qtree.zip
- 4059544并行数据转换为串行数据.rar
- office2016outlook解除附件大小限制.reg
- wangyue20075_10403409.zip
- 3qdnep.rar
- wangyonggui1223_1787815.zip
- 专业课试题集.pdf
- questasim.txt
- modelsim-win64-10.7-se.txt
- 分支限界法求解单源最短路径
评论
共有 条评论