From: "Olivier D." Date: 2004-09-10T04:00:42+09:00 Subject: Re: Réf. : ASCII, RSA AND BIGNUM Be careful, I'm a nuby, but I've found a few things: On 2004-09-09, Barry Sperling wrote: > # PRINTS ASCII OF ARRAY, CURRENTLY BACKWARDS AND 8 CHARACTERS SPECIFICALLY > def convert_to_text( num ) > ... > end If you want to convert ASCII chars from 0 to 99 in one line, you can do: def convert_to_text(num) num.to_s.reverse.scan(/\d\d?/).map { |c| c.reverse.to_i.chr }.join.reverse end BUT it's dirty and you're limited to decimal values <= 99. Why not use String#hex instead: # give this function an hexa string def hex_to_text(string) string.scan(/../).map { |c| c.hex.chr }.join end puts hex_to_text("61626364") > # THE TEXT, TO BE ENCRYPTED AND SENT ALONG WITH THE PUBLIC KEY > # LIMITED TO 8 CHAR, ALL WITH ASCII VALUES BELOW 100 > s = "GO SKINS" > asc_of_text = 0 > s.each_byte do |a| #TAKING EACH CHAR AS A 2-DIGIT NUM AND CREATING A > print( a ); print( ' ' ) # LARGE NUM WITH EACH PAIR OF DIGITS > # BEING THE ASCII > asc_of_text *= 100 # OF THE STRING, LEFT-MOST 2 DIGITS BEING > #THE FIRST LETTER > asc_of_text += a > end > puts You can do this shorter: s = "GO SKINS" asc = s.split(//).map { |c| "%02d" % c[0] }.join No comments for the crypto part, I'll have to read my lessons again... And a last comment for the code: remove all the for loops, like for i in 0..(string.length - 1) and change them into 'each' calls with blocks associated. With Strings you can use 'each'. With Arrays you can use 'each', 'each_index'. And with all the Enumerables (String, Array...): each_with_index. -- Olivier D.