Encoder/Decoder Challenge/Source 05-13-2012, 03:01 PM
#1
Hello again, community! I had a challenge for myself to create a encoder and a decoder program using timestamps. So, now I will present it to you with two options. 1 - Read the code and use it, or, 2 - Take the challenge for yourself. Here are the specs for the encoder:
asks for string, number, randomizes each character from the number, and displays the output.
Same thing with the decoder, it just does the opposite. :ok:
Anyway, here is my code if you don't want to take the challenge:
and
asks for string, number, randomizes each character from the number, and displays the output.
Same thing with the decoder, it just does the opposite. :ok:
Anyway, here is my code if you don't want to take the challenge:
Spoiler:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
const int SIZE = 25565;
char encode(char toEncode[SIZE], int timeStamp)
{
srand(timeStamp);
int i = 0,
j = 0;
while(toEncode[i] != '\0')
{
if(static_cast<int>(toEncode[i]) % 2)
toEncode[i] += rand() % (10 + 1) * 2;
else
toEncode[i] += rand() % (20 + 10) * 2 + 1;
i++;
j++;
}
for(i = 0; i <= j; i++)
cout << toEncode[i] << " ";
return 0;
}
int main()
{
char carray[SIZE] = { },
tstamp;
cout << "string: ";
cin.getline(carray, SIZE);
cout << "time stamp: ";
cin >> tstamp;
encode(carray, tstamp);
getch();
return 0;
}and
Spoiler:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
const int SIZE = 25565;
char decode(char toEncode[SIZE], int timeStamp)
{
srand(timeStamp);
int i = 0,
j = 0;
while(toEncode[i] != '\0')
{
if(static_cast<int>(toEncode[i]) % 2)
toEncode[i] -= rand() % (10 + 1) * 2;
else
toEncode[i] -= rand() % (20 + 10) * 2 + 1;
i++;
j++;
}
for(i = 0; i <= j; i++)
cout << toEncode[i] << " ";
return 0;
}
int main()
{
char carray[SIZE] = { },
tstamp;
cout << "string: ";
cin >> carray;
cout << "time stamp: ";
cin >> tstamp;
decode(carray, tstamp);
getch();
return 0;
}
To hack is a skill, but a skill may or may not be to hack.




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
]