Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Viginere

def viginere(string)
	countArr = []
	count=0
	newString=[]
	for i in 1..string.length-1 do
		for x in i..string.length do
			newString.push(string[x])
		end
		for y in 0..newString.length do
			if string[y] == newString[y]
				count = count + 1
			end
		end
		countArr.push([i, count])
		count=0
		newString=[]
	end
	
	countArr = countArr.sort {|x,y| y[1] <=> x[1] }
	mods = []
	for x in 0..20 do
		mods.push([x+2,0])
		for i in 0..9 do
			if countArr[i][0]%(x+2) == 0
				mods[x][1]=mods[x][1]+1
			end
		end
	end
	mods = mods.sort {|x,y| y[1] <=> x[1] }
	return mods
end

def encrypt(string, key)
    result = []
    i = 0
    for x in 0..string.length-1 do
	  pass_char = key[i]
	  xor = string[x].ord ^ pass_char.ord
	  result.push(xor)
	  i+=1
	  if i == (key.size)
	    i = 0
	  end
	end
	return result
end

password = ["J","O","N"]
input = "had i the heavens embroidered cloths enwrought with golden and silver light the blue and the dim and the dark cloths of night and light and the half light i would spread the cloths under your feet but i being poor have only my dreams i have spread my dreams under your feet tread softly because you tread on my dreams"
newText = encrypt(input, password)

result = viginere(newText)

for x in 0..result.length-1 do
	puts result[x][0].to_s + ": " + result[x][1].to_s + " matches"
end

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.