Tài liệu hướng dẫn thực hành

Courses - Cryptography

User Rating: / 1
PoorBest 

Tài liệu hướng dẫn thực hành môn "Nhập môn lý thuyết mã hoá thông tin".

Ngôn ngữ: Python

 

Nội dung: gồm 6 chương:

  1. Tổng quan về Python (yêu cầu tự đọc)
  2. Mật mã cổ điển
  3. Mã đối xứng hiện đại và mã công khai
  4. Hàm băm mật mã
  5. Hệ mã logarit rời rạc
  6. Chữ ký điện tử
Đánh giá: kiểm tra dựa trên tất cả các bài tập thực hành (không kể bài tập 30, 31, 32, 33).

 

 

Comments  

 
+1 # Thong D. Nguyen 2010-10-07 06:32
Code:def cesar(p,k):
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
c='';
for j in range(len(p)):
c += abc[(abc.index(p[j])+k)%len(abc)];
return c;

Mã Cesar
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 06:45
Code:def cesar2(p,k):
k_cur = k;
c = p;
while k_cur > 0:
c = cesar(c, k_cur % 10);
k_cur /= 10;
return c;

Mã Cesar 2
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 09:56
Code:def cesar2_d(c,k):
k_cur = int(str(k)[::-1]);
p = c;
while k_cur > 0:
p = cesar_d(p, k_cur % 10);
k_cur /= 10;
return p;

Mã Cesar 2 Decode
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 09:38
Code:def cesar_d(c,k):
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
p='';
for i in range(len(c)):
p += abc[(abc.index(c)-k)%len(abc)];
return p;

Cesar Decode
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 06:59
Code:k='DLRYVOHEZXWPTBGFJQNMUSKACI';

def subs(p,k):
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if len(abc) != len(k):
return '';
c='';
for j in range(len(p)):
c += k[abc.index(p[j])];
return c;

Mã thay thế
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 10:21
Code:def subs_d(c,k):
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if len(abc) != len(k):
return '';
p='';
for j in range(len(c)):
p += abc[k.index(c[j])];
return p;

Mã thay thế (Decode)
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 07:51
Code:def affine(p,k):
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
a=k[0];
b=k[1];
c='';
for i in range(len(p)):
x = abc.index(p);
c += abc[(a*x+b)%len(abc)];
return c;

Mã Affine
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 09:12
Code:def affine6(p,k):
return affine(cesar(cesar(p, k[1]), k[0]), k);

Mã Affine 6
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-07 09:20
Code:def affine7(p,k):
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
c = '';
for j in range(len(p)):
ki = [k[0], abc.index(cesar(p[j], k[1]))];
c += affine(p[j], k);
return c;

Mã Affine 7
Reply | Reply with quote | Quote
 
 
0 # Thong D. Nguyen 2010-10-08 07:50
Code:def egcd(a, b):
"""Returns a triple (g, x, y), such that ax + by = g = gcd(a,b). Assumes a, b >= 0."""
if a == 0:
return (b, 0, 1)
else:
g, y, x = egcd(b % a, a)
return (g, x - (b // a) * y, y)

def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
return None
else:
return x % m


Modular inverse
Source: www.algorithmist.com/index.php/Modular_inverse
Reply | Reply with quote | Quote
 

Add comment


Security code
Refresh

Idioms

  • Every day is not saturday. (Sông có khúc, người có lúc)
  • Don't count your chickens, before they are hatched. (Chưa đỗ ông Nghè đã đe Hàng tổng)

Who's online

We have 8 guests online

Location

 38.107.179.217
 38.107.179.217
Search Bot
 unknown unkno

Relax

Site Ranking


Increase your website traffic with Attracta.com

Quick Search

This Day in History

Poll

What is your current operating system?
 

Weather

Newsletter

Copyright © 2012 Thong D. Nguyen. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.