U E D R , A S I H C RSS

데블스캠프2011/다섯째날/Cryptography (rev. 1.4)

데블스캠프2011/다섯째날/Cryptography

Python Client

import socket
addr = ('255.255.255.255', 3333)

UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Create socket
UDPSock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
print ('Enter your message:')
print ('- Empty message to stop this client.')

while True:
    data = raw_input('>> ')
    if len(data) == 0:
        break
    else:
        if UDPSock.sendto(data, addr):
            print ("Sending message '%s'..." % data)

UDPSock.close()
print ('Client stopped.')



import socket

rcv_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
    rcv_sock.bind(("", 3333))
except:
    print "Error at Binding"

while True:
    print "Listening..."
    data, addr = rcv_sock.recvfrom(3333)
    print "Got %s" % data



키 생성

두 개의 p != q인 큰 소수 p와 q를 선택한다.
n <- p*q
φ(n) <- (p-1)*(q-1)
1 < e < φ(n)이면서 φ(n)과 서로소인 e를 선택한다.
d <- e–1 mod φ(n)

(e, n) 은 공개키, d는 개인키

암호화

C : 암호문, P : 평문
C = Pe mod n

복호화

C : 암호문, P : 평문
P = Cd mod n

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:11
Processing time 0.0256 sec