Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created September 20, 2012 04:29
Show Gist options
  • Save arn-e/3753985 to your computer and use it in GitHub Desktop.
Save arn-e/3753985 to your computer and use it in GitHub Desktop.
decrypt single key
def decrypt_single_key(key,value)
offset,decrypted, off_i = key,[] , 1
value.split('').each_with_index do |val, i|
val.ord >= 97 && val.ord <= 122 ? dist = (val.ord + offset % 26) : dist = val.ord
dist > 122 && dist!= val.ord ? (decrypted.push (122 - (26 - (dist - 122))).chr) : (decrypted.push dist.chr)
end
return decrypted.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment