I just started the matasano security challenge, and thought about learning IO at the same time. So now, i'm stuck on challenge 1 where I need to convert a string to base64.
Anyway i've come to the point where i need to convert from binary to decimal, here is my aproach:
binToDec := method( bin, <-- program does not enter this method
dec := 0
rem := 0
i := 0
while ( bin != 0,
rem = bin % 10
bin = bin / 10
dec = dec + rem * 2 pow( i )
i = i + 1
)
return dec
)
toBase64Ascii := method( slice,
tmp := ""
for( a, 0, slice size, <-- construct a string to use with asNumber
tmp = tmp .. slice at( a )
)
dec := binToDec( tmp asNumber ) <-- the line that make the whole thing crash
)
for ( a, 0, bin size, 6,
tmp := toBase64Ascii( bin slice( a, a + 6 )
***some more code***
)
there is no error message or anything, the program just hangs indefinitely.
From the documentation: asNumber Returns the receiver converted to a number. Initial whitespace is ignored.
So i must say i'm quite confused here, what is happening ?
I would have done some more research but io is imposible to google for...
I'm not sure what the expected input and output of your
binToDecmethod is, butis likely an infinite loop.
binis a floating point number which is repeatedly divided by10, which does not mean that it ever reaches0.Notice that there are
asBase64andfromBase64methods on sequences.