KRzA/4-lab/bob.rb
Marcin Woźniak 17237eab0a
Updated
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
2020-12-03 21:21:19 +01:00

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