-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.sage
70 lines (55 loc) · 1.39 KB
/
demo.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
'''
Created on Apr 26, 2013
@author: elmasry
'''
def execute():
global N,e,d, username
attach "moneypenny.sage"
init()
file1 = "imnothere.txt"
global secretfile
user1 = "bond"
user2 = "bram"
username = user1
#print "Erzeuge Schlüssel..."
p = nextprime(2^4)
q = nextprime(2^5);
if p ==q: print "p=q ist verboten!"
else: print "OK. (p<>q)"
N = p*q;
L = (p-1)*(q-1);
p = q = None
while True:
e = random(3,L-2)
#print "Teste: e=" + str(e)
if GCD(e,L) == 1: break
#print "Gefunden: e=" + str(e)
d = 1/e % L
L = None
#checkmail()
#y = readmail();
secret = [N,d];
public = [N,e];
print "Schlüssel erzeugt."
print "Übersetze Nachricht."
x = text2num("Hi ich heiße niemand")
if x >= N: print "Nachricht zu lang!"
print "Verschlüsseln..."
y = x.powermod(e, N)
clearInbox()
mailto( "[email protected]", "Hier mo", N, e, y)
username = user2
getkey(user1)
msg = "blablablabla"
x = text2num(msg)
y = x.powermod(e, N)
mailto(user1 + "@bit.uni-bonn.de", "vom Bram", N, e, y)
username = user1
checkmail()
y = readmail(-1)
getkey(msgN,msge)
print "Entschlüsseln..."
z = y.powermod(d, N)
print "Übersetze Zahl."
print num2text(z)