ven.rb:27:in `encrypt': undefined method `-' for "a":String
(NoMethodError)
from ven.rb:27:in `map'
from ven.rb:27:in `encrypt'
from ven.rb:38
still############33here is my code complete its some cipher
def decrypt(data)
ndata=data.clone
srand(5000)
a = ndata.size-1 # control loop
while a>-1
temp=ndata[a]
temp-=rand(10)
temp= 26-((temp.abs)%26) if temp<0
temp= temp%26 if temp>-1
ndata[a]=temp+97a-=1
end
return ndataend
def encrypt(data)
ndata=data.dup
a = ndata.size-1
srand(5000)
ndata = ndata.split(//).map{ |c| ((c-97)+rand(10))%26
}.join
At this point 'c' is a string: split(//) returns an array of strings.
String does not have a '-' method, so you should first convert to
integer thus:
ndata = ndata.split(//).map{ |c| ((c.to_i-97)+rand(10))%26
}.join
And possibly convert back into chars:
ndata = ndata.split(//).map{ |c| (((c.to_i-97)+rand(10))%26).chr
}.join
#end # this code down here works but its to messy
# while a>-1
# ndata[a]=
((ndata[a]-97)+rand(10))%26
# a-=1
#end
return ndata
end
it=String.new("abcdefghijklmnop")print decrypt(encrypt(it))
###################
and i get the error above with the new added code. Sorry to be such a
pain.
···
Becker