Transforms a rail-fence-encrypted Text to its original

assert "fgounbmtcieehkh".unrail(4) == "fuckingbehemoth"

Property definitions

crypto :: basic_ciphers $ Text :: unrail
	# Transforms a rail-fence-encrypted Text to its original
	#
	#     assert "fgounbmtcieehkh".unrail(4) == "fuckingbehemoth"
	fun unrail(depth: Int): Text do
		var dots = "." * length
		var arr = new FlatBuffer.from(dots)
		var start = 0
		var paces = depth.unrail_paces
		for i in [0..depth[ do
			var lp = paces[i].first
			var rp = paces[i].second
			var pos = i
			var l = true
			while pos < length do
				arr[pos] = chars[start]
				if l then
					pos += lp
					l = false
				else
					pos += rp
					l = true
				end
				start += 1
			end
		end
		return arr.to_s
	end
lib/crypto/basic_ciphers.nit:130,2--156,4