#include <stdio.h>
#include <string.h>
#define AMOUNT 10 //63
#define MAX 50
int main(int argc,char *argv[]){
int cracked=0; //boolean to control whether the program has cracked the code or not
int r=0; //row index
int c[MAX]; //row column indices
int f=1; //furthest row segment reached
char *actualCode="056667421"; //code the agorithm is attempting to emit
char code[MAX]; //string to store calculated code
char codex[AMOUNT]={'0','1','2','3','4','5','6','7','8','9'}; //could be replaced easily with letters of the alphabet
int i=0;
while(i<MAX){
c[i]=-1;
i++;
}
while(!cracked){
r=0;
while(r<f){
while(c[r]<AMOUNT){
code[r]=codex[c[r]];
printf("%s ",code);
if(strcmp(code,actualCode)){ //if this is true, then the it's been cracked
printf("\nCode is: %s\n",code);
cracked=1;
break;
}else{
c[r]++;
}
}
r++;
}
if(c[f]==AMOUNT-1){ //has f reached 9?
f++; //then move onto next digit
c[f]=0; //set next digit to 0
}else{
c[f]++; //up f value
}
r=0;
while(r<f){ //set previous values before current f to 0
c[r]=0;
code[r]=codex[c[r]];
r++;
}
code[f]=codex[c[f]];
}
while(1); //stop program from closing
return 0;
}
The code has been developed under Xcode(Mac OS X IDE by Apple). When the program in debugged under Xcode and I open up GDB it says:
The Debugger has exited with status 0.
[Session started at 2011-10-02 14:40:16 +0100.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
run
[Switching to process 17381]
Running…
Code is:
...And doesn't display the code although it has supposedly been cracked(passed the integrity test).
Why is it doing that?
Thanks in advance.
A neutron walked into a bar and said "How much for a pint of beer?". The bartender replied "For you, today sir, no charge.".
A particle said to another particle "I think I've lost an electron.". The other particle replied "What, are you positive?".
It's a special setting that FBI embedded into all compilers that would prevent you from making code cracking programs.. Son, you can't crack code if you can't debug your own code.
strcmp returns 0 on success, which would be a logical 'false': http://www.cplusplus.com/reference/clib ... ng/strcmp/. Right now your algorithm exits immediately because your 'if' check will pass when the strings are *not* identical.
Add an ! in your if and it should work, unless i missed some other error.
cypher1554R wrote:It's a special setting that FBI embedded into all compilers that would prevent you from making code cracking programs.. Son, you can't crack code if you can't debug your own code.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
szdarkhack wrote:strcmp returns 0 on success, which would be a logical 'false': http://www.cplusplus.com/reference/clib ... ng/strcmp/. Right now your algorithm exits immediately because your 'if' check will pass when the strings are *not* identical.
Add an ! in your if and it should work, unless i missed some other error.
Well I've done that and now I get loads of numbers preceded by a slash in the form of the code variable.
You're initializing the entire c[] to -1, and then using that to index into the codex[] array. I'm surprised it didn't crash, but random garbage output should give you the hint that you're out of bounds on some array. Change the initialization to 0, it should fix that. By the way, the debugger is there for a reason...
szdarkhack wrote:You're initializing the entire c[] to -1, and then using that to index into the codex[] array. I'm surprised it didn't crash, but random garbage output should give you the hint that you're out of bounds on some array. Change the initialization to 0, it should fix that. By the way, the debugger is there for a reason...
The column array value is never used when it is in a state of -1, the -1 is just a placeholder. The numbers are correctly looping but it seems to be adding the string "\300_\377" to the end of all the code attempts?
A neutron walked into a bar and said "How much for a pint of beer?". The bartender replied "For you, today sir, no charge.".
A particle said to another particle "I think I've lost an electron.". The other particle replied "What, are you positive?".
If you actually look at what the code is outputting, it's just doing 0,1,2... up to 99 followed by \300_\377, then 000 to 999 followed by _\377, then 0000 to 9999 followed by \377, then just normal numbers. the change in the numbers isn't entirely sequential, but that's the basic pattern; this means that it is NOT cracking the code, just outputting the combinations it's tried. Also, you in fact ARE using all c[n]'s when they're -1 ("code[r]=codex[c[r]];"). Anyway, this can't really crack any codes, as it's really only outputting data it's already been given.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Ginto8 wrote:If you actually look at what the code is outputting, it's just doing 0,1,2... up to 99 followed by \300_\377, then 000 to 999 followed by _\377, then 0000 to 9999 followed by \377, then just normal numbers. the change in the numbers isn't entirely sequential, but that's the basic pattern; this means that it is NOT cracking the code, just outputting the combinations it's tried. Also, you in fact ARE using all c[n]'s when they're -1 ("code[r]=codex[c[r]];"). Anyway, this can't really crack any codes, as it's really only outputting data it's already been given.
By the time it uses a c[n] it's already > -1. The system is basically the number system backwards. It's designed to crack any char code consisting of ANY type of char from the codex.
EDIT: Once the algorithm is fixed it will work on data that isn't already in the immediate memory of the program.
A neutron walked into a bar and said "How much for a pint of beer?". The bartender replied "For you, today sir, no charge.".
A particle said to another particle "I think I've lost an electron.". The other particle replied "What, are you positive?".
int i=0;
while(i<MAX){
c[i]=-1; [b]// <- All c[] is initialized to -1[/b]
i++;
}
while(!cracked){
r=0; [b]// <- still -1[/b]
while(r<f){ [b]// <- hmm, still -1[/b]
while(c[r]<AMOUNT){ [b]// <- yeap, STILL -1[/b]
code[r]=codex[c[r]]; [b]// <- BOOM!! You're dead. Out of bounds.[/b]
printf("%s ",code);
[/quote]
Yeah...