Understanding

int i;
for( i = 0 ; i < str.length() ; i++ )
ans += ascii_to_bin(str[i]) + " ";
cout<<ans<<endl<<endl;


string ascii_to_bin(char ch)
{
// get the ascii value of ch
int ascii = (int)ch;
string bin = "";
// loop untill ascii becomes 0
while(ascii > 0)
{
if(ascii % 2 == 0)
bin = "0" + bin;
else
bin = "1" + bin;
ascii /= 2;
}
if(bin.length() < 8)
{
int i;
for( i = 0 ; i < 8 - bin.length() ; i++ )
bin = "0" + bin;
}
return bin;
}

Hi all I am currently doing an assignment and reading my friends code. it is to decrypt
Enter the string to encrypt: 011010100110010101101110
output = jen
What is the question?


PS. Please use code tags and intuitive indentation when posting code. See http://www.cplusplus.com/articles/jEywvCM9/
01101010
is 106
is j in the ascii table.

its just converting binary back to decimal and extracting the character from the standard table of text characters.

Its not in any way encryption.
Topic archived. No new replies allowed.