Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-23-2007, 03:42 PM
s7s s7s is offline
Newbie
 
Join Date: Jun 2007
Posts: 5
Rep Power: 0
s7s is on a distinguished road
Default decryption problem!!

Hello programmers

in fact i have a problem with my decrypting code !!

the encryption works fine with the APPLY_M function but when i do the reverse for the decription (APPLY_M_Reverse) it show wrong result !!

something missing or the order of things is not right..??

i need help plzzz

this is my code:
Code:
#include <stdio.h> 

typedef unsigned char uint8;

// Mixing function constant C

#define CSC_C00 0xb7

#define CSC_C01 0xe1

#define CSC_C02 0x51

#define CSC_C03 0x62

#define CSC_C04 0x8a

#define CSC_C05 0xed

#define CSC_C06 0x2a

#define CSC_C07 0x6a

// Mixing function constant C prime

#define CSC_C10 0xbf

#define CSC_C11 0x71

#define CSC_C12 0x58

#define CSC_C13 0x80

#define CSC_C14 0x9c

#define CSC_C15 0xf4

#define CSC_C16 0xf3

#define CSC_C17 0xc7


// P: the permutation table
uint8 tbp[256]={

		0x29,0x0d,0x61,0x40,0x9c,0xeb,0x9e,0x8f,

		0x1f,0x85,0x5f,0x58,0x5b,0x01,0x39,0x86,

		0x97,0x2e,0xd7,0xd6,0x35,0xae,0x17,0x16,

		0x21,0xb6,0x69,0x4e,0xa5,0x72,0x87,0x08,

		0x3c,0x18,0xe6,0xe7,0xfa,0xad,0xb8,0x89,

		0xb7,0x00,0xf7,0x6f,0x73,0x84,0x11,0x63,

		0x3f,0x96,0x7f,0x6e,0xbf,0x14,0x9d,0xac,

		0xa4,0x0e,0x7e,0xf6,0x20,0x4a,0x62,0x30,

		0x03,0xc5,0x4b,0x5a,0x46,0xa3,0x44,0x65,

		0x7d,0x4d,0x3d,0x42,0x79,0x49,0x1b,0x5c,

		0xf5,0x6c,0xb5,0x94,0x54,0xff,0x56,0x57,

		0x0b,0xf4,0x43,0x0c,0x4f,0x70,0x6d,0x0a,

		0xe4,0x02,0x3e,0x2f,0xa2,0x47,0xe0,0xc1,

		0xd5,0x1a,0x95,0xa7,0x51,0x5e,0x33,0x2b,

		0x5d,0xd4,0x1d,0x2c,0xee,0x75,0xec,0xdd,

		0x7c,0x4c,0xa6,0xb4,0x78,0x48,0x3a,0x32,

		0x98,0xaf,0xc0,0xe1,0x2d,0x09,0x0f,0x1e,

		0xb9,0x27,0x8a,0xe9,0xbd,0xe3,0x9f,0x07,

		0xb1,0xea,0x92,0x93,0x53,0x6a,0x31,0x10,

		0x80,0xf2,0xd8,0x9b,0x04,0x36,0x06,0x8e,

		0xbe,0xa9,0x64,0x45,0x38,0x1c,0x7a,0x6b,

		0xf3,0xa1,0xf0,0xcd,0x37,0x25,0x15,0x81,

		0xfb,0x90,0xe8,0xd9,0x7b,0x52,0x19,0x28,

		0x26,0x88,0xfc,0xd1,0xe2,0x8c,0xa0,0x34,

		0x82,0x67,0xda,0xcb,0xc7,0x41,0xe5,0xc4,

		0xc8,0xef,0xdb,0xc3,0xcc,0xab,0xce,0xed,

		0xd0,0xbb,0xd3,0xd2,0x71,0x68,0x13,0x12,

		0x9a,0xb3,0xc2,0xca,0xde,0x77,0xdc,0xdf,

		0x66,0x83,0xbc,0x8d,0x60,0xc6,0x22,0x23,

		0xb2,0x8b,0x91,0x05,0x76,0xcf,0x74,0xc9,

		0xaa,0xf1,0x99,0xa8,0x59,0x50,0x3b,0x2a,

		0xfe,0xf9,0x24,0xb0,0xba,0xfd,0xf8,0x55,

		};

// The Message
uint8 m[8] = {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};

// The 9 keys
uint8 k[72] = {
		0x45,0xfd,0x13,0x7a,0x4e,0xdf,0x9e,0xc4,
		0x1d,0xd4,0x3f,0x03,0xe6,0xf7,0x56,0x4c,
		0xeb,0xe2,0x67,0x56,0xde,0x99,0x37,0xc7,
		0x96,0x17,0x04,0xe9,0x45,0xba,0xd4,0xfb,
		0x0b,0x60,0xdf,0xe9,0xef,0xf4,0x73,0xd4,
		0x76,0xd3,0xe7,0xcf,0x52,0xc4,0x66,0xcf,
		0x75,0xec,0x8c,0xef,0x76,0x7d,0x3a,0x0d,
		0x82,0xda,0x33,0x37,0xb5,0x98,0xfd,0x6d,
		0xfb,0xd8,0x20,0xda,0x8d,0xc8,0xaf,0x8c
		};

void APPLY_M(uint8 cl, uint8 cr, uint8 adl, uint8 adr)
{

	uint8 tmpx,tmprx,tmpy;

	tmpx=m[adl]^cl; 


	tmprx=(tmpx<<1)^(tmpx>>7); 


	tmpy=m[adr]^cr; 


	// yl
	m[adl]=tbp[(tmprx&0x55)^tmpx^tmpy]; 

	// yr

	m[adr]=tbp[tmprx^tmpy];


}

void APPLY_M_Reverse(uint8 cl, uint8 cr, uint8 adl, uint8 adr)
{

	uint8 tmpx,tmprx,tmpy,P, tmprP,rxl;

	tmpx=m[adl]^cl; 


	tmprx=(tmpx<<1)^(tmpx>>7); 


	tmpy=m[adr]^cr; 


	// xl
	P = tbp[tmpx]^tbp[tmpy];
	tmprP = (P<<1)^(P>>7);
	m[adl]=(tmprP&0xaa)^P;
	
	// xr
	rxl = (m[adl]<<1)^(m[adl]>>7);

	m[adr]=rxl^tbp[tmpy];

	

}
void enc_csc(uint8 m[8],uint8 k[72]) 
{

	int i,j;
	for(i=0;i<8;i++) 
	{
		printf(" m%d = ",i);
		for(j=0;j<8;j++) printf("%x",m[j]);
		printf(" \n");
	
		// mix with the first 8 keys, one key at each round
		APPLY_M(k[0+8*i],k[1+8*i],0,1);

		APPLY_M(k[2+8*i],k[3+8*i],2,3);

		APPLY_M(k[4+8*i],k[5+8*i],4,5);

		APPLY_M(k[6+8*i],k[7+8*i],6,7);

	
		// mix with the mixing function constant c
		APPLY_M(CSC_C00,CSC_C01,0,2);

		APPLY_M(CSC_C02,CSC_C03,4,6);

		APPLY_M(CSC_C04,CSC_C05,1,3);

		APPLY_M(CSC_C06,CSC_C07,5,7);

	
		// mix with the mixing function constant c'
		APPLY_M(CSC_C10,CSC_C11,0,4);

		APPLY_M(CSC_C12,CSC_C13,1,5);

		APPLY_M(CSC_C14,CSC_C15,2,6);

		APPLY_M(CSC_C16,CSC_C17,3,7);
	

	}
	printf(" m%d = ",i);
	for(i=0;i<8;i++) 
	printf("%x",m[i]);
	printf(" \n");
	
	// XOR with the key

	for(i=0;i<8;i++) m[i]^=k[64+i];


}

void dec_csc(uint8 m[8],uint8 k[72]) 
{

	int i,j;
	// XOR with the key

	for(i=0;i<8;i++) m[i]^=k[64+i];

	printf(" m%d = ",i);
	for(i=0;i<8;i++) 
	printf("%x",m[i]);
	printf(" \n");
	
	for(i=7;i>=0;i--) 
	{
		// mix with the mixing function constant c'
		APPLY_M_Reverse(CSC_C10,CSC_C11,0,4);

		APPLY_M_Reverse(CSC_C12,CSC_C13,1,5);

		APPLY_M_Reverse(CSC_C14,CSC_C15,2,6);

		APPLY_M_Reverse(CSC_C16,CSC_C17,3,7);
	
		// mix with the mixing function constant c
		APPLY_M_Reverse(CSC_C00,CSC_C01,0,2);

		APPLY_M_Reverse(CSC_C02,CSC_C03,4,6);

		APPLY_M_Reverse(CSC_C04,CSC_C05,1,3);

		APPLY_M_Reverse(CSC_C06,CSC_C07,5,7);
		
		// mix with the first 8 keys, one key at each round
		APPLY_M_Reverse(k[0+8*i],k[1+8*i],0,1);

		APPLY_M_Reverse(k[2+8*i],k[3+8*i],2,3);

		APPLY_M_Reverse(k[4+8*i],k[5+8*i],4,5);

		APPLY_M_Reverse(k[6+8*i],k[7+8*i],6,7);

	
		printf(" m%d = ",i);
		for(j=0;j<8;j++) printf("%x",m[j]);
		printf(" \n");

	}

}
int main()
{
	int j,i;
	//uint8* finalkey;

//	for(j=0;j<8;j++)
//	{
		enc_csc(m,k);
		
		printf("\n The ciphertext is: ");
		for(i=0;i<8;i++)
		{
			printf("%x",m[i]);			
		}
		printf("\n");
//		m[j]= m[j]+1;
		
//	}

//	for(j=0;j<8;j++)
//	{
		dec_csc(m,k);
		
		printf("\n The decrypted ciphertext is: ");
		for(i=0;i<8;i++)
		{
			printf("%x",m[i]);
		}
		printf("\n");
//		m[j]= m[j]-1;
		
//	}
	return 0;
}

am sorry for bothering ,, but plzzzzzz help me

regard,
s7s

Last edited by v0id; 06-23-2007 at 04:35 PM. Reason: Added code-tags.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-23-2007, 04:39 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

What is wrong? Doesn't it compile, do you get warnings, is it wrong output, and so on. Please specify it a bit.

At the moment I don't have much time, but I'll maybe take a deeper look at your code tomorrow. I don't say I can help you, because I'm not the best in encryption and decryption, but I'll give it a try. But first of all; try reading what I wrote in the top of this post.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-23-2007, 05:22 PM
s7s s7s is offline
Newbie
 
Join Date: Jun 2007
Posts: 5
Rep Power: 0
s7s is on a distinguished road
Default

it compiles , but it give me wrong result not as wht it should be!!

for example, when i run it ,
for the first part :
it should print the m[i] from 0 to 8
then print the cipher
and this part is correct till now..

but for the second part (decryption)
it should print back the above sequence in reverse :
m[i] from 8 to 0 and then the plain text

but it gives me m[8] right and the other is wrong

so ,, i hope i can get a help!! plzzzzzzzzzz
i need to have it work before monday morning
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-24-2007, 07:17 AM
s7s s7s is offline
Newbie
 
Join Date: Jun 2007
Posts: 5
Rep Power: 0
s7s is on a distinguished road
Default

where are ya people !!!
someone help me ,plllzzzz!!!

i wish i can get a help before tomorrow ,,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-25-2007, 12:07 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

If you could give us a clue as to which algorithm you are implementing, that might help. Given that you are using an unknown algorithm, it will be difficult to help you determine where you are going wrong.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 06-26-2007, 08:17 AM
s7s s7s is offline
Newbie
 
Join Date: Jun 2007
Posts: 5
Rep Power: 0
s7s is on a distinguished road
Default

Quote:
Originally Posted by WingedPanther View Post
If you could give us a clue as to which algorithm you are implementing, that might help. Given that you are using an unknown algorithm, it will be difficult to help you determine where you are going wrong.
am using the CS_Cipher , the encryption function with the help of APPLY_M would do the encryption process of a 64 bit plaintext and a key of 128 bit size. for the decryption the APPLY_M_Reverse() is used to do the opposit of the encryption process.

i guess my problem is with the order of doing things in the APPLY_M_Reverse it should be exactly the opposit of the APPLY_M() ..

i hope this would be more clearer

am trying to solve the problem by myself and nevermind if someone may help me..

kind regard,

s7s ..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-26-2007, 12:25 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

A brief Google search failed to turn up an algorithm. There are a couple things I would check, however.
1) Make sure that your encoding is producing the correct result. Since it was part of a contest submitted to the federal government, there should be samples of what the encoded string should be for various unencoded strings.
2) Make sure you are actually reversing the process correctly. It's amazingly easy to screw up inverting a function (having done so a few times myself).
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-27-2007, 11:16 AM
s7s s7s is offline
Newbie
 
Join Date: Jun 2007
Posts: 5
Rep Power: 0
s7s is on a distinguished road
Default

Quote:
Originally Posted by WingedPanther View Post
A brief Google search failed to turn up an algorithm. There are a couple things I would check, however.
1) Make sure that your encoding is producing the correct result. Since it was part of a contest submitted to the federal government, there should be samples of what the encoded string should be for various unencoded strings.
2) Make sure you are actually reversing the process correctly. It's amazingly easy to screw up inverting a function (having done so a few times myself).
Dear WingedPanther,
am sure that the encryption results is true, but not sure about the decryption.. thanks anyhow..

regard,
s7s
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar UI Problem Needs Tackling adriyel C# Programming 2 04-06-2008 08:46 AM
i have a problem please help me!!!???? stack Java Help 8 09-22-2007 04:17 PM
[C] Comparison problem Alhazred C and C++ 1 08-29-2007 05:58 AM
A small problem in the output The_Master C and C++ 3 12-13-2006 01:04 PM


All times are GMT -5. The time now is 02:51 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads