C programming help! To do encoding of a input string

yssmile

Junior Member
Joined
Oct 14, 2015
Messages
8
Reaction score
0
i have a 60 characters input string to convert using a substitution table:
1312e7972714d01a46664a3523366a2f58560b42c485853674561c360d77

Index 0 1 2 3 4 5 6 7 8 9 a b c d e f
S-box 0 2 4 c 9 a 3 7 e 1 0 f 8 6 b d

Example: when input = 1 ,will convert to output = 2;
input a, output = 0

i have write a code as such, but output is totally messed up,need expert to correct my code...thx alot guys

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>

main()

{
char input[60] = { "1312e7972714d01a46664a3523366a2f58560b42c485853674561c360d77" };

char sbox[8][16] = {
{ '2', '4', 'c', '5', '9', 'a', '3', '7', 'e', '1', '0', 'f', '8', '6', 'b', 'd' },
{ '7', 'e', 'a', '4', '1', 'd', '9', 'f', '2', 'b', '6', '0', 'c', '5', '8', '3' },
{ '3', '8', 'f', '1', 'a', '6', '5', 'b', 'd', 'e', '4', '2', '7', '0', '9', 'c' },
{ '8', 'f', '7', '9', '3', 'd', '4', 'b', 'c', '2', '0', 'a', '1', '5', '6', 'e' },
{ '1', 'f', '8', '3', 'c', '0', 'b', '6', '2', '5', '4', 'e', '9', 'a', '7', 'd' },
{ '1', 'd', 'f', '0', 'e', '8', '2', 'c', '7', '4', 'b', 'a', '3', '5', '9', '6' },
{ 'a', '3', '4', '7', 'b', '8', 'd', '2', '6', 'c', 'f', 'e', '0', '5', '1', '9' },
{ '3', 'c', '4', '2', '7', 'a', '0', '8', '5', 'b', 'f', '1', 'd', '6', '9', 'e' }
};

int box_id,i;

for (i = 0; i < 60; i++)
{

printf("%c", sbox[0][input]);

}
system("pause");
}
 

normalperson

Member
Joined
Jun 21, 2015
Messages
271
Reaction score
0
for (i = 0; i < 60; i++)
{

printf("%c", sbox[0][input - '0']);

}


Might be a start
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top