KRzA/5-rsa/bob.rb

49 lines
821 B
Ruby
Raw Normal View History

#!/usr/bin/ruby
#
######################################
#
# Marcin Woźniak
# s434812
#
#####################################
require 'socket'
load 'modul1.rb'
while true
# Reading a message
#message = File.read("message.txt")
message="823789137891789217389173981378913789137289"
# Turning on server
sock = TCPServer.new(3000)
client = sock.accept
#Greetings
client.puts "Hej Alice"
# Receiving public key
n = client.gets.gsub(/\n$/, '')
e = client.gets.gsub(/\n$/, '')
pubKeyAlice=[n,e]
puts
puts "pubKey Alice: " + pubKeyAlice.inspect
puts
# Solving a cipher
cipher = betterExponentiation(message.to_i,e.to_i,n.to_i)
puts "Cipher: " + cipher.inspect
puts "Message " + message.inspect
# Sending cipher to Alice
client.puts cipher
# Close socket
sock.close
end