Tries to find key using frequency analysis on all possible plaintexts.

Populates self.key

Property definitions

crapto :: xor $ SingleByteXorCipher :: find_key
	# Tries to find key using frequency analysis on all possible plaintexts.
	# Populates `self.key`
	fun find_key do

		# Accumulate best result
		var max = 0.0
		var best = 0

		# Iterate on possible values for a byte
		var xor_b = new Bytes.with_capacity(1)
		for b in [0 .. 255] do
			# Need `Bytes` to pass to xor
			xor_b[0] = b

			# Xor and evaluate result
			var xored = ciphertext.xorcipher(xor_b)
			var result = xored.to_s.english_scoring
			if result > max then
				max = result
				best = b
			end
		end

		self.key = best

	end
lib/crapto/xor.nit:23,2--48,4