vendor/gems/rubyzip-0.9.1/lib/quiz1/t/solutions/James Edward Gray II/solitaire.rb
# Unkeyed deck - Keystream Step 1
Unkeyed deck - Keystream Step 1
Unkeyed deck - Keystream Step 1
def encrypt(message)
	message = message.upcase.tr("^A-Z", "")
	i = 5
	while i < message.size
		message[i, 0] = " "
		i += 6
	end
	message += "X" while message.rindex(" ") != message.size - 6
	key_stream = generate(message.count("^ "))
	values = message.split("").map { |letter| letter[0] - ?A + 1 }
	key_values = key_stream.split("").map { |letter| letter[0] - ?A + 1 }
	values.each_with_index do |value, index|
		next if value < 0
		values[index] = value + key_values[index]
		values[index] -= 26 if values[index] > 26
	end
	message = (values.map { |number| (number - 1 + ?A).chr }).join("")
	return message
end
def encrypt ( message ) message = message . upcase . tr ( "^A-Z" , "" ) i = 5 while i < message . size message [ i , 0 ] = " " i += 6 end message += "X" while message . rindex ( " " ) != message . size - 6 key_stream = generate ( message . count ( "^ " ) ) values = message . split ( "" ) . map { | letter | letter [ 0 ] - ?A + 1 } key_values = key_stream . split ( "" ) . map { | letter | letter [ 0 ] - ?A + 1 } values . each_with_index do | value , index | next if value < 0 values [ index ] = value + key_values [ index ] values [ index ] -= 26 if values [ index ] > 26 end message = ( values . map { | number | ( number - 1 + ?A ) . chr } ) . join ( "" ) return message end
Unkeyed deck - Keystream Step 1
Unkeyed deck - Keystream Step 1
# Step 1 # Step 2 # Step 3 # Step 4 # Step 5 # Step 6
message
<not_specific>