Forum

> > CS2D > Scripts > Ask About lua :)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Ask About lua :)

6 replies
To the start Previous 1 Next To the start

old Ask About lua :)

seciawang
User Off Offline

Quote
Hi,can i ask?
how to know this code? i think this is binary code
010001010111001001111010011000010010000001010011011000110110000101110010011011000110010101110100
i want to break this code with lua code...
anyone can help me?

Thanks
Sorry if im bad english

old Re: Ask About lua :)

DC
Admin Off Offline

Quote
From where did you get this code? You can't simply translate it because you don't know the format. I mean: Are those bytes/ASCII chars? Or integers? Or floats? Or mixed stuff?

Edit:
I assume that it is an ASCII encoded string. So 8 bits form a byte and each byte can be translated into a letter using an ASCII table.
edited 1×, last 05.03.13 01:06:09 pm

old Re: Ask About lua :)

EngiN33R
Moderator Off Offline

Quote
1
2
3
yournumber = "010001010111001001111010011000010010000001010011011000110110000101110010011011000110010101110100" -- this is the binary number

decoded = tonumber(tostring(yournumber),2)

Assuming that's a number. If it's an encoded string, then you need this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
function bintoascii(bin,big) -- set big to true if it's big endian, leave be if it's little endian
	local str=""

	if not big then bin=bin:reverse() end
	local j=1
	for i=8,#bin,8 do
		local ascii=tonumber(bin:sub(j,i),2)
		str=str..string.char(ascii)
		j=i+1
	end
	
	return str
end

In your case it is a string, and using the function above with Big Endian mode on we can see that this is "Erza Scarlet".
edited 3×, last 05.03.13 01:21:54 pm

old Re: Ask About lua :)

x0rh4x
User Off Offline

Quote
Hey, here is a code which converts your binary code into a for a human readable string

1
2
3
4
5
6
7
local bin = "010001010111001001111010011000010010000001010011011000110110000101110010011011000110010101110100";

function bin2text(bin)
	return bin:gsub('('..('[01]'):rep(8)..')', function(b) return string.char(tonumber(b, 2)) end);
end

print(bin2text(bin));

You can test it at http://www.lua.org/cgi-bin/demo

- x0rh4x.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview