Help with Ruby method - how to phrase


#1

I'm trying to build a method that takes in a string, and returns the previous letters of the string. For example, "abc" would return "zab"
This is what I have so far:

def decrypt(string)
index = 0
alphabet = "abcdefghijklmopqrstuvqxyz"
while index < string.length
if string[index] == " "
puts string[index] = " "
else
puts
end
index += 1
end
end


#2

I understand what you're trying to do.
Do you know anything about ascii?
wouldn't that be what you need for this?


#3

I don't know about ascii, I'm just starting out in Ruby. Is there any beginner way to solve this problem? maybe using .index on alphabet string?


#4

actually, i looked more into this, and ruby might be a good language to do this in.
This isn't actually a beginner problem, and i don't know that there is an easy way to go through this, but i found some other examples of people writing caesar ciphers in ruby, and you could actually do a list of something like:

l_alphabet = ("a".."z").to_a

I don't know if this gives you a sort of idea for what you could use an index for .
I could direct you to examples of caesar ciphers, but i don't know if that might be cheating.
Are you doing this for fun/experience or for something else?


#5

Well I found a good sort of walkthrough to build it, I don't know if this will help :confused:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.