Page 1 of 1
Code Cracker Problems
Posted: Sun Oct 02, 2011 8:42 am
by FunkyFermion
Hello ladies and gentlemen. For the past few days I have been developing a C program that can crack codes.
Here's the code:
Code: Select all
#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.
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 2:22 pm
by cypher1554R
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.
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 2:23 pm
by szdarkhack
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.
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 2:49 pm
by dandymcgee
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.
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 2:56 pm
by FunkyFermion
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.
[Session started at 2011-10-02 20:48:17 +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 18245]
Running…
0\300_\377 1\300_\377 2\300_\377 3\300_\377 4\300_\377 5\300_\377 6\300_\377 7\300_\377 8\300_\377 9\300_\377 00\300_\377 10\300_\377 20\300_\377 30\300_\377 40\300_\377 50\300_\377 60\300_\377 70\300_\377 80\300_\377 90\300_\377 01\300_\377 11\300_\377 21\300_\377 31\300_\377 41\300_\377 51\300_\377 61\300_\377 71\300_\377 81\300_\377 91\300_\377 02\300_\377 12\300_\377 22\300_\377 32\300_\377 42\300_\377 52\300_\377 62\300_\377 72\300_\377 82\300_\377 92\300_\377 03\300_\377 13\300_\377 23\300_\377 33\300_\377 43\300_\377 53\300_\377 63\300_\377 73\300_\377 83\300_\377 93\300_\377 04\300_\377 14\300_\377 24\300_\377 34\300_\377 44\300_\377 54\300_\377 64\300_\377 74\300_\377 84\300_\377 94\300_\377 05\300_\377 15\300_\377 25\300_\377 35\300_\377 45\300_\377 55\300_\377 65\300_\377 75\300_\377 85\300_\377 95\300_\377 06\300_\377 16\300_\377 26\300_\377 36\300_\377 46\300_\377 56\300_\377 66\300_\377 76\300_\377 86\300_\377 96\300_\377 07\300_\377 17\300_\377 27\300_\377 37\300_\377 47\300_\377 57\300_\377 67\300_\377 77\300_\377 87\300_\377 97\300_\377 08\300_\377 18\300_\377 28\300_\377 38\300_\377 48\300_\377 58\300_\377 68\300_\377 78\300_\377 88\300_\377 98\300_\377 09\300_\377 19\300_\377 29\300_\377 39\300_\377 49\300_\377 59\300_\377 69\300_\377 79\300_\377 89\300_\377 99\300_\377 000_\377 100_\377 200_\377 300_\377 400_\377 500_\377 600_\377 700_\377 800_\377 900_\377 900_\377 910_\377 920_\377 930_\377 940_\377 950_\377 960_\377 970_\377 980_\377 990_\377 001_\377 101_\377 201_\377 301_\377 401_\377 501_\377 601_\377 701_\377 801_\377 901_\377 901_\377 911_\377 921_\377 931_\377 941_\377 951_\377 961_\377 971_\377 981_\377 991_\377 002_\377 102_\377 202_\377 302_\377 402_\377 502_\377 602_\377 702_\377 802_\377 902_\377 902_\377 912_\377 922_\377 932_\377 942_\377 952_\377 962_\377 972_\377 982_\377 992_\377 003_\377 103_\377 203_\377 303_\377 403_\377 503_\377 603_\377 703_\377 803_\377 903_\377 903_\377 913_\377 923_\377 933_\377 943_\377 953_\377 963_\377 973_\377 983_\377 993_\377 004_\377 104_\377 204_\377 304_\377 404_\377 504_\377 604_\377 704_\377 804_\377 904_\377 904_\377 914_\377 924_\377 934_\377 944_\377 954_\377 964_\377 974_\377 984_\377 994_\377 005_\377 105_\377 205_\377 305_\377 405_\377 505_\377 605_\377 705_\377 805_\377 905_\377 905_\377 915_\377 925_\377 935_\377 945_\377 955_\377 965_\377 975_\377 985_\377 995_\377 006_\377 106_\377 206_\377 306_\377 406_\377 506_\377 606_\377 706_\377 806_\377 906_\377 906_\377 916_\377 926_\377 936_\377 946_\377 956_\377 966_\377 976_\377 986_\377 996_\377 007_\377 107_\377 207_\377 307_\377 407_\377 507_\377 607_\377 707_\377 807_\377 907_\377 907_\377 917_\377 927_\377 937_\377 947_\377 957_\377 967_\377 977_\377 987_\377 997_\377 008_\377 108_\377 208_\377 308_\377 408_\377 508_\377 608_\377 708_\377 808_\377 908_\377 908_\377 918_\377 928_\377 938_\377 948_\377 958_\377 968_\377 978_\377 988_\377 998_\377 009_\377 109_\377 209_\377 309_\377 409_\377 509_\377 609_\377 709_\377 809_\377 909_\377 909_\377 919_\377 929_\377 939_\377 949_\377 959_\377 969_\377 979_\377 989_\377 999_\377 0000\377 1000\377 2000\377 3000\377 4000\377 5000\377 6000\377 7000\377 8000\377 9000\377 9000\377 9100\377 9200\377 9300\377 9400\377 9500\377 9600\377 9700\377 9800\377 9900\377 9900\377 9910\377 9920\377 9930\377 9940\377 9950\377 9960\377 9970\377 9980\377 9990\377 0001\377 1001\377 2001\377 3001\377 4001\377 5001\377 6001\377 7001\377 8001\377 9001\377 9001\377 9101\377 9201\377 9301\377 9401\377 9501\377 9601\377 9701\377 9801\377 9901\377 9901\377 9911\377 9921\377 9931\377 9941\377 9951\377 9961\377 9971\377 9981\377 9991\377 0002\377 1002\377 2002\377 3002\377 4002\377 5002\377 6002\377 7002\377 8002\377 9002\377 9002\377 9102\377 9202\377 9302\377 9402\377 9502\377 9602\377 9702\377 9802\377 9902\377 9902\377 9912\377 9922\377 9932\377 9942\377 9952\377 9962\377 9972\377 9982\377 9992\377 0003\377 1003\377 2003\377 3003\377 4003\377 5003\377 6003\377 7003\377 8003\377 9003\377 9003\377 9103\377 9203\377 9303\377 9403\377 9503\377 9603\377 9703\377 9803\377 9903\377 9903\377 9913\377 9923\377 9933\377 9943\377 9953\377 9963\377 9973\377 9983\377 9993\377 0004\377 1004\377 2004\377 3004\377 4004\377 5004\377 6004\377 7004\377 8004\377 9004\377 9004\377 9104\377 9204\377 9304\377 9404\377 9504\377 9604\377 9704\377 9804\377 9904\377 9904\377 9914\377 9924\377 9934\377 9944\377 9954\377 9964\377 9974\377 9984\377 9994\377 0005\377 1005\377 2005\377 3005\377 4005\377 5005\377 6005\377 7005\377 8005\377 9005\377 9005\377 9105\377 9205\377 9305\377 9405\377 9505\377 9605\377 9705\377 9805\377 9905\377 9905\377 9915\377 9925\377 9935\377 9945\377 9955\377 9965\377 9975\377 9985\377 9995\377 0006\377 1006\377 2006\377 3006\377 4006\377 5006\377 6006\377 7006\377 8006\377 9006\377 9006\377 9106\377 9206\377 9306\377 9406\377 9506\377 9606\377 9706\377 9806\377 9906\377 9906\377 9916\377 9926\377 9936\377 9946\377 9956\377 9966\377 9976\377 9986\377 9996\377 0007\377 1007\377 2007\377 3007\377 4007\377 5007\377 6007\377 7007\377 8007\377 9007\377 9007\377 9107\377 9207\377 9307\377 9407\377 9507\377 9607\377 9707\377 9807\377 9907\377 9907\377 9917\377 9927\377 9937\377 9947\377 9957\377 9967\377 9977\377 9987\377 9997\377 0008\377 1008\377 2008\377 3008\377 4008\377 5008\377 6008\377 7008\377 8008\377 9008\377 9008\377 9108\377 9208\377 9308\377 9408\377 9508\377 9608\377 9708\377 9808\377 9908\377 9908\377 9918\377 9928\377 9938\377 9948\377 9958\377 9968\377 9978\377 9988\377 9998\377 0009\377 1009\377 2009\377 3009\377 4009\377 5009\377 6009\377 7009\377 8009\377 9009\377 9009\377 9109\377 9209\377 9309\377 9409\377 9509\377 9609\377 9709\377 9809\377 9909\377 9909\377 9919\377 9929\377 9939\377 9949\377 9959\377 9969\377 9979\377 9989\377 9999\377 00000 10000 20000 30000 40000 50000 60000 70000 80000 90000 90000 91000 92000 93000 94000 95000 96000 97000 98000 99000 99000 99100 99200 99300 99400 99500 99600 99700 99800 99900 99900 99910 99920 99930 99940 99950 99960 99970 99980 99990 00001 10001 20001 30001 40001 50001 60001 70001 80001 90001 90001 91001 92001 93001 94001 95001 96001 97001 98001 99001 99001 99101 99201 99301 99401 99501 99601 99701 99801 99901 99901 99911 99921 99931 99941 99951 99961 99971 99981 99991 00002 10002 20002 30002 40002 50002 60002 70002 80002 90002 90002 91002 92002 93002 94002 95002 96002 97002 98002 99002 99002 99102 99202 99302 99402 99502 99602 99702 99802 99902 99902 99912 99922 99932 99942 99952 99962 99972 99982 99992 00003 10003 20003 30003 40003 50003 60003 70003 80003 90003 90003 91003 92003 93003 94003 95003 96003 97003 98003 99003 99003 99103 99203 99303 99403 99503 99603 99703 99803 99903 99903 99913 99923 99933 99943 99953 99963 99973 99983 99993 00004 10004 20004 30004 40004 50004 60004 70004 80004 90004 90004 91004 92004 93004 94004 95004 96004 97004 98004 99004 99004 99104 99204 99304 99404 99504 99604 99704 99804 99904 99904 99914 99924 99934 99944 99954 99964 99974 99984 99994 00005 10005 20005 30005 40005 50005 60005 70005 80005 90005 90005 91005 92005 93005 94005 95005 96005 97005 98005 99005 99005 99105 99205 99305 99405 99505 99605 99705 99805 99905 99905 99915 99925 99935 99945 99955 99965 99975 99985 99995 00006 10006 20006 30006 40006 50006 60006 70006 80006 90006 90006 91006 92006 93006 94006 95006 96006 97006 98006 99006 99006 99106 99206 99306 99406 99506 99606 99706 99806 99906 99906 99916 99926 99936 99946 99956 99966 99976 99986 99996 00007 10007 20007 30007 40007 50007 60007 70007 80007 90007 90007 91007 92007 93007 94007 95007 96007 97007 98007 99007 99007 99107 99207 99307 99407 99507 99607 99707 99807 99907 99907 99917 99927 99937 99947 99957 99967 99977 99987 99997 00008 10008 20008 30008 40008 50008 60008 70008 80008 90008 90008 91008 92008 93008 94008 95008 96008 97008 98008 99008 99008 99108 99208 99308 99408 99508 99608 99708 99808 99908 99908 99918 99928 99938 99948 99958 99968 99978 99988 99998 00009 10009 20009 30009 40009 50009 60009 70009 80009 90009 90009 91009 92009 93009 94009 95009 96009 97009 98009 99009 99009 99109 99209 99309 99409 99509 99609 99709 99809 99909 99909 99919 99929 99939 99949 99959 99969 99979 99989 99999 000000 100000 200000 300000 400000 500000 600000 700000 800000 900000 900000 910000 920000 930000 940000 950000 960000 970000 980000 990000 990000 991000 992000 993000 994000 995000 996000 997000 998000 999000 999000 999100 999200 999300 999400 999500 999600 999700 999800 999900 999900 999910 999920 999930 999940 999950 999960 999970 999980 999990 000001 100001 200001 300001 400001 500001 600001 700001 800001 900001 900001 910001 920001 930001 940001 950001 960001 970001 980001 990001 990001 991001 992001 993001 994001 995001 996001 997001 998001 999001 999001 999101 999201 999301 999401 999501 999601 999701 999801 999901 999901 999911 999921 999931 999941 999951 999961 999971 999981 999991 000002 100002 200002 300002 400002 500002 600002 700002 800002 900002 900002 910002 920002 930002 940002 950002 960002 970002 980002 990002 990002 991002 992002 993002 994002 995002 996002 997002 998002 999002 999002 999102 999202 999302 999402 999502 999602 999702 999802 999902 999902 999912 999922 999932 999942 999952 999962 999972 999982 999992 000003 100003 200003 300003 400003 500003 600003 700003 800003 900003 900003 910003 920003 930003 940003 950003 960003 970003 980003 990003 990003
It should go like this:
0
1
2
3
4
5
6
7
8
9
00
10
20
30
40
50
60
70
80
90
01
11
21
31
41
51
61
71
81
91
02
12
22
32
42
52
62
72
82
92
03
...etc....
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 3:16 pm
by szdarkhack
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...
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 3:33 pm
by FunkyFermion
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?
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 4:10 pm
by Ginto8
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.
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 4:29 pm
by FunkyFermion
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.
Re: Code Cracker Problems
Posted: Sun Oct 02, 2011 5:45 pm
by szdarkhack
FunkyFermion wrote:
By the time it uses a c[n] it's already > -1.
Is that so? Look closely...
FunkyFermion wrote:
Code: Select all
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...