36 lines
603 B
Ruby
Executable File
36 lines
603 B
Ruby
Executable File
#!/usr/bin/ruby
|
|
#
|
|
######################################
|
|
#
|
|
# Marcin Woźniak
|
|
# s434812
|
|
#
|
|
#####################################
|
|
|
|
require 'socket'
|
|
|
|
load 'modul1.rb'
|
|
|
|
|
|
while true
|
|
sock = TCPServer.new(3000)
|
|
client = sock.accept
|
|
client.puts "Hej Alice"
|
|
|
|
p = [client.gets.gsub(/\n$/, '')].pack("b*").to_i
|
|
x = [client.gets.gsub(/\n$/, '')].pack("b*").to_i
|
|
|
|
puts p.inspect
|
|
puts x.inspect
|
|
|
|
message = File.read("message.txt")
|
|
c = OpenSSL::Cipher::AES.new(256, 'CBC')
|
|
c.encrypt
|
|
iv = p.first(16)
|
|
c.key = x
|
|
encrypted = c.update(message) + c.final
|
|
|
|
puts encrypted.inspect
|
|
sock.close
|
|
end
|