示例#1
0
private_key = 67
public_key = pow(
    generator, private_key, modulo
)  # Create public key based off power of generator ^ private % modulo

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))  # Create socket to assigned IP and port
    s.listen()  # Begin listening on socket

    conn, addr = s.accept(
    )  # Assign conn and addr variables when socket is reached
    print('Connection from:', addr)  # Print connected host address

    client_public_key = conn.recv(1024)
    print('Received client public key:', int(client_public_key))

    conn.sendall(str(public_key).encode())
    shared_secret = pow(int(client_public_key), private_key, modulo)
    print('Shared secret:', str(shared_secret))

    message = ''
    while True:
        message += str(conn.recv(1024).decode())
        if not conn.recv(1024):
            break
    print('Received cipher text:', message)

    decrypted = caesarCipher.caesar(message, shared_secret, 'd')
    print('Decrypted cipher text:', decrypted)

    s.close()
示例#2
0
    clientConn.sendall(str(public_key).encode())
    clientSharedSecret = pow(int(client_public_key), private_key, modulo)
    print('Alice\'s shared secret:', str(clientSharedSecret))

    ### RECEIVE MESSAGE FROM ALICE ###
    clientMessage = ''
    while True:
        clientMessage += str(clientConn.recv(1024).decode())
        if not clientConn.recv(1024):
            break
    print('Received cipher text:', clientMessage)
    serverSocket.close()

### DECRYPT AND MANIPULATE RESPONSE FROM ALICE ###
decryptedClientMessage = caesarCipher.caesar(clientMessage, clientSharedSecret,
                                             'd')
print('Decrypted cipher text:', decryptedClientMessage)
manipulatedMessage = decryptedClientMessage.replace('dawn', 'noon')
print('Manipulated Message:', manipulatedMessage)

# Impersonates Alice and acts as a client for Bob
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as clientSocket:
    ### ESTABLISH CONNECTION WITH BOB ###
    clientSocket.connect((HOST, client_PORT))
    clientSocket.sendall(str(public_key).encode())

    server_public_key = clientSocket.recv(1024).decode()
    print('Received Bob\'s public key:', str(server_public_key))

    serverSharedSecret = pow(int(server_public_key), private_key, modulo)
    print('Bob\'s Shared secret:', serverSharedSecret)
# Simple Caesar cipher brute force program
import caesarCipher

alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%/.'
message = '6@ $2a2/.zb/4 ya a5ya a6!2 y 0#!$960ya21 .a/b4492 dy. z26@4 0y//621 #@ d6a5 4/2ya2/ 52ya a5y@ 2c2/ 6@ a52 56452.a 06/092., z2ad22@ a52 $y/a62. #3 /[email protected], a52 3/2@05, !y/fy 321#/#c@y, a52 A.y/2c605, y@1 #a52/., 1/#d@21 y. b.by9 zf a52 zbgg6@4 #3 a52 0#b/a 1/#@2.x Zba a52 0y9!, 9beb/6#b. 9632 #3 $2a2/.zb/4, 0#@02/@21 #@9f yz#ba $5y@a#!. y@1 /23920a6#@. #3 /2y9 9632, d2@a #@ 6@ 6a. #91 dyf y@1 !y12 6a 5y/1, 2e02$a zf y 4/2ya 233#/a, a# /2y96g2 a52 1y@42/ y@1 a52 163360b9a $#.6a6#@ #3 a52 /b..6y@ $2#$92x A52/2 d2/2 a52 .y!2 /202$a6#@. y@1 zy99., a52 .y!2 3/2@05 a52ya2/, a52 .y!2 0#b/a 6@a2/2.a. y@1 .2/c602 6@a2/2.a. y@1 6@a/64b2. y. b.by9x #@9f 6@ a52 c2/f 56452.a 06/092. d2/2 yaa2!$a. !y12 a# 822$ 6@ !6@1 a52 163360b9a62. #3 a52 y0aby9 $#.6a6#@x .a#/62. d2/2 d56.$2/21 #3 5#d 16332/2@a9f a52 ad# 2!$/2..2. z25yc21 6@ a52.2 163360b9a 06/[email protected] A52 2!$/2.. !y/fy, 0#@02/@21 3#/ a52 d293y/2 #3 a52 05y/6ayz92 y@1 21b0ya6#@y9 [email protected]#@. b@12/ 52/ $ya/#@y42, 5y1 46c2@ 16/20a6#@. a5ya a52f .5#b91 y99 z2 /2!#c21 a# 8ygy@, y@1 a52 a56@4. z29#@46@4 a# a52.2 [email protected]#@. 5y1 y9/2y1f z22@ $y0821 b$x A52 2!$/2.. 296.yz2a5, 5#d2c2/, d52@ y.821 d5ya [email protected]/b0a6#@. .52 d#b91 z2 $92y.21 a# 46c2- d6a5 52/ 05y/y0a2/6.a60 /b..6y@ $ya/6#a6.! 5y1 /2$9621 a5ya .52 0#b91 46c2 @# 16/20a6#@. yz#ba .aya2 [email protected]#@. 3#/ a5ya dy. a52 y33y6/ #3 a52 .#c2/264@, zba y. 3y/ y. .52 $2/.#@y99f dy. 0#@02/@21 .52 d#b91 z2 a52 9y.a a# %b6a $2a2/.zb/4x'

# Checks every key based on length of the alphabet
for key in range(len(caesarCipher.alphabet)):
    print(key, '--->', caesarCipher.caesar(message, key, 'd'))
示例#4
0
import caesarCipher
import socket

HOST = '127.0.0.1'  # Local IP
PORT = 65432  # Assigned Port
generator = 1024
modulo = 199
private_key = 56
public_key = pow(generator, private_key, modulo)
message = 'This message is encrypted using Caesar cipher.'

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    s.sendall(str(public_key).encode())

    server_public_key = s.recv(1024).decode()
    print('Received server public key:', str(server_public_key))

    shared_secret = pow(int(server_public_key), private_key, modulo)
    print('Shared secret:', shared_secret)

    cipher = caesarCipher.caesar(message, shared_secret, 'e')
    s.sendall(str(cipher).encode())

    s.close()
示例#5
0
    conn, addr = s.accept()  # Accept connections and store the address
    print('Connection from', addr)  # Print the Connection to screen

    client_public_key = conn.recv(
        1024)  # Store the public key up to buffer size 1024
    print('Received client public key:',
          int(client_public_key))  # Print client pub key to screen

    conn.sendall(str(
        public_key).encode())  # Send UTF-8 encoded server public key to client
    shared_secret = pow(int(client_public_key), private_key,
                        modulo)  # Generate shared secret
    print('Shared secret=' +
          str(shared_secret))  # Print shared secret to screen

    message = ''
    while True:
        message += str(conn.recv(1024).decode(
        ))  # Decode UTF-8 encoded text received from client and add to message
        if not conn.recv(
                1024):  # Break connection when no more text is being sent
            break
    print('Received cipher text:',
          message)  # Print received cipher text message
    decrypted = caesarCipher.caesar(
        message, shared_secret,
        'd')  # Call cipher to decode message with shared secret
    print('Decrypted cipher text:',
          decrypted)  # Print decrypted text to screen
    s.close()
示例#6
0
import socket
import caesarCipher
HOST = '127.0.0.1'
PORT = 17777
generator = 2048
modulo = 199
private_key = 145
public_key = pow(generator, private_key, modulo)
meetingTimeMessage = 'Meet me at dawn'

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))     # Connect to server on host:port
    s.sendall(str(public_key).encode())     # Send UTF-8 encoded public key to server

    server_public_key = s.recv(1024).decode()   # Store UTF-8 decoded server public key that was received
    print('Received server public key:', str(server_public_key))    # Print the server's public key

    shared_secret = pow(int(server_public_key), private_key, modulo)    # Generate shared secret from received pub key
    print('Shared secret:', shared_secret)  # Print shared secret

    encryptedMessage = caesarCipher.caesar(meetingTimeMessage, shared_secret, 'e')    # Call cipher to encrypt text to be sent
    s.sendall(str(encryptedMessage).encode())     # Send all the encrypted text to server