-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsskma.py
71 lines (57 loc) · 2.38 KB
/
sskma.py
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
71
'''
Simple Shared Key Mutual Authentication
REG NO: P15/55175/2012
COURSE: CSC 411 - Computer Network Security
'''
##############
# Shared Key #
##############
privateKey = [38369,39203]
publicKey = [19625,39203]
########################
# Alice Challenges Bob #
########################
aliceHasAuthenticated = False
print('##########\nAlice Challenges Bob\n##########')
#Alice sends challenge to Bob
aliceSentChallenge = int(input("Alice, enter challenge: "))
aliceSentCypherChallenge = pow(aliceSentChallenge, publicKey[0], publicKey[1]) # (pT ^ e) mod N
print('The encrypted challenge is: {}'.format(aliceSentCypherChallenge))
#Bob receives & decrypts challenge
bobReceivedCypherChallenge = int(input("Bob, enter the received encrypted challenge: "))
bobReceivedChallenge = pow(bobReceivedCypherChallenge, privateKey[0], privateKey[1]) # (cT ^ d) mod N
print('The decrypted challenge is: {}'.format(bobReceivedChallenge))
# if Bob's received challenge == Alice's sent challenge
if aliceSentChallenge == bobReceivedChallenge:
aliceHasAuthenticated = True
print('Alice: Yes, it is you Bob!')
else:
print('Alice: You are not Bob, who are you?')
print("\n")
########################
# Bob Challenges Alice #
########################
bobHasAuthenticated = False
print('##########\nBob Challenges Alice\n##########')
#Bob sends challenge to Alice
bobSentChallenge = int(input("Bob, enter challenge: "))
bobSentCypherChallenge = pow(bobSentChallenge, publicKey[0], publicKey[1]) # (pT ^ e) mod N
print('The encrypted challenge is: {}'.format(bobSentCypherChallenge))
#Alice receives & decrypts challenge
aliceReceivedCypherChallenge = int(input("Alice, enter the received encrypted challenge: "))
aliceReceivedChallenge = pow(aliceReceivedCypherChallenge, privateKey[0], privateKey[1]) # (cT ^ d) mod N
print('The decrypted challenge is: {}'.format(aliceReceivedChallenge))
# if Alice's received challenge == Bob's sent challenge
if bobSentChallenge == aliceReceivedChallenge:
bobHasAuthenticated = True
print('Bob: Yes, it is you Alice!')
else:
print('Bob: You are not Alice, who are you?')
print("\n")
###################################
# Print success on authentication #
###################################
if aliceHasAuthenticated and bobHasAuthenticated:
print('Both users have authenticated each others identity. Communication can resume.')
else:
print('Authentication failed for both users.')