Solution to problem Based, picoCTF2019:

Abhishek Kumar
2 min readMar 13, 2020

The problem goes like this:

To get truly 1337, you must understand different data encodings, such as hexadecimal or binary. Can you get the flag from this program to prove you are on the way to becoming 1337? Connect with nc 2019shell1.picoctf.com 29594.

Solution:

Once you connect to the port by the command:

nc 2019shell1.picoctf.com 29594.

You will be given some binary numbers actually they are lowercase latin characters encoded in 8 bits(1 byte). I wrote a C++ program to readily give u the text no matter how long the text they give:

#include<bits/stdc++.h>

using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

string str;
while (1) {
cin >> str;
int cnt = 0;
reverse(str.begin(), str.end());
for(int i = 0; i < 8; i++) {
if (str[i] == ‘1’)
cnt += pow(2,i);
}
cout << (char)(cnt);
cout << endl;
}
return 0;
}

Once u type in the decrypted text, now u r given a text in octal for which the code I wrote is:

#include<bits/stdc++.h>

using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

string str;
while (1) {
cin >> str;
int cnt = 0;
reverse(str.begin(), str.end());
for(int i = 0; i < 2; i++) {
cnt += ((str[i]-’0')*pow(8,i));
}
cout << (char)(cnt);
cout << endl;
}
return 0;
}

And finally, u r given to decrypt a hexadecimal message for which the code is given below:

#include<bits/stdc++.h>

using namespace std;int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

string str;
map<char,int> mp;
for(char ch = ‘a’, i = 0; ch <= ‘f’; ch++, i++) {
mp[ch] = 10+i;
}
cin >> str;
int n = str.length();
for(int i = 0; i < n; i += 2) {
int cnt = 0;
if (str[i] >= ‘0’ && str[i] <= ‘9’) {
cnt += (str[i]-’0')*16;
} else {
cnt += (mp[str[i]]*16);
}
//now for the (i+1)th character
if (str[i+1] >= ‘0’ && str[i+1] <= ‘9’) {
cnt += (str[i+1]-’0');
} else {
cnt += mp[str[i+1]];
}
cout << (char)(cnt) << endl;
}
return 0;
}

Though the text picoCTF are relatively small and if u r fast enough u can calculate and decrypt it. But, u have long messages u should go for writing a small script.

Happy hacking && Happy Programming.

--

--