CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Ciphering again

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
No_Fear
Guest







Ciphering again
PostPosted: Fri Jan 10, 2003 1:43 pm     Reply with quote

Hi there,
I posted a message about this topic before.I got a reply from a friend here.(Thank you).I noticed that the code is in asm and i dont know how to convert it in c to use it in ccs c compiler.Can anyone advice me something in c please.Because i wrote all my code in c and i need to complete it in c.My main problem is, i want to cipher a string and decrypt it back.For example :
//String = "Hello"
Enc(String,Key);
...//String = "a012b3c5aa2100be"
...
Dec(String,Key);
//String = "Hello"
Thank you.
P.S. Maybe pic implementation of blowfish, twofish, rcX can be useful for me but i couldn't find them on net.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10596
Sherpa Doug
Guest







Re: Ciphering again
PostPosted: Fri Jan 10, 2003 1:48 pm     Reply with quote

:=I noticed that the code is in asm and i dont know how to convert it in c to use it in ccs c compiler.Can anyone advice me something in c please.Because i wrote all my code in c and i need to complete it in c.

How about using #ASM & #ENDASM to embed the assembly code in your C? Then you only have to handle getting the data in and out. To be a good PIC C programmer you should know a little about assembly.

___________________________
This message was ported from CCS's old forum
Original Post ID: 10597
Mark DSylva
Guest







Re: Ciphering again
PostPosted: Fri Jan 10, 2003 2:29 pm     Reply with quote

:=:=I noticed that the code is in asm and i dont know how to convert it in c to use it in ccs c compiler.Can anyone advice me something in c please.Because i wrote all my code in c and i need to complete it in c.
:=
:=How about using #ASM & #ENDASM to embed the assembly code in your C? Then you only have to handle getting the data in and out. To be a good PIC C programmer you should know a little about assembly.
:=

That's exactly how I expected he would do it.

Hello No_Fear,
The person who wrote that code in assembly language probably put some effort into optimising it's execution speed. If you try to convert it back into C, I wouldn't be surprised if it ends up running slower.

Also, it's easy to use that code if you use #asm and #endasm as mentioned.

Mark
___________________________
This message was ported from CCS's old forum
Original Post ID: 10598
No_Fear
Guest







Re: Ciphering again
PostPosted: Fri Jan 10, 2003 5:26 pm     Reply with quote

Thanks for all reply.Yea, i agree with you i must embed the code but i will encode some data with my pic and decrypt it back with my program which i am writing with borland c++ builder.And most of the trouble is, when i use some asm codes in bcb i got lots of trouble with it.I mean i want to use encryption/decryption algorithm both pic and bcb.If i can't find an instant solution, then i will embed some codes to my pic software and i will use asm codes with my bcb.Anyway, if you see something suits me, just ring.
Thanks.

:=:=:=I noticed that the code is in asm and i dont know how to convert it in c to use it in ccs c compiler.Can anyone advice me something in c please.Because i wrote all my code in c and i need to complete it in c.
:=:=
:=:=How about using #ASM & #ENDASM to embed the assembly code in your C? Then you only have to handle getting the data in and out. To be a good PIC C programmer you should know a little about assembly.
:=:=
:=
:=That's exactly how I expected he would do it.
:=
:=Hello No_Fear,
:=The person who wrote that code in assembly language probably put some effort into optimising it's execution speed. If you try to convert it back into C, I wouldn't be surprised if it ends up running slower.
:=
:=Also, it's easy to use that code if you use #asm and #endasm as mentioned.
:=
:=Mark
___________________________
This message was ported from CCS's old forum
Original Post ID: 10603
Mark DSylva
Guest







Re: Ciphering again
PostPosted: Fri Jan 10, 2003 9:01 pm     Reply with quote

<font face="Courier New" size=-1>You just have to locate the TEA algorithm in C if you want to compile it for the PC.

Here it is:

/************************************************

The Tiny Encryption Algorithm (TEA) by
David Wheeler and Roger Needham of the
Cambridge Computer Laboratory

**** ANSI C VERSION ****

Notes:

TEA is a Feistel cipher with XOR and
and addition as the non-linear mixing
functions.

Takes 64 bits of data in v[0] and v[1].
Returns 64 bits of data in w[0] and w[1].
Takes 128 bits of key in k[0] - k[3].

TEA can be operated in any of the modes
of DES. Cipher Block Chaining is, for example,
simple to implement.

n is the number of iterations. 32 is ample,
16 is sufficient, as few as eight may be OK.
The algorithm achieves good dispersion after
six iterations. The iteration count can be
made variable if required.

Note this is optimised for 32-bit CPUs with
fast shift capabilities. It can very easily
be ported to assembly language on most CPUs.

delta is chosen to be the real part of (the
golden ratio Sqrt(5/4) - 1/2 ~ 0.618034
multiplied by 2^32).

************************************************/

void encipher(unsigned long *const v,unsigned long *const w,
const unsigned long *const k)
{
register unsigned long y=v[0],z=v[1],sum=0,delta=0x9E3779B9,
a=k[0],b=k[1],c=k[2],d=k[3],n=32;

while(n-->0)
{
sum += delta;
y += (z<<4)+a ^ z+sum ^ (z>>5)+b;
z += (y<<4)+c ^ y+sum ^ (y>>5)+d;
}

w[0]=y; w[1]=z;
}

void decipher(unsigned long *const v,unsigned long *const w,
const unsigned long *const k)
{
register unsigned long y=v[0],z=v[1],sum=0xC6EF3720,
delta=0x9E3779B9,a=k[0],b=k[1],c=k[2],
d=k[3],n=32;

/* sum = delta<<5, in general sum = delta * n */

while(n-->0)
{
z -= (y<<4)+c ^ y+sum ^ (y>>5)+d;
y -= (z<<4)+a ^ z+sum ^ (z>>5)+b;
sum -= delta;
}

w[0]=y; w[1]=z;
}

// end of TEA algorithm

Here's a link where you can find the above source:

<a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank"> <a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank"> <a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank">http://vader.brad.ac.uk/tea/tea.shtml</a></a></a>

I hope that helps. (I'll probably use a cipher in a product soon, so I've been collecting info on them)

Mark






:=Thanks for all reply.Yea, i agree with you i must embed the code but i will encode some data with my pic and decrypt it back with my program which i am writing with borland c++ builder.And most of the trouble is, when i use some asm codes in bcb i got lots of trouble with it.I mean i want to use encryption/decryption algorithm both pic and bcb.If i can't find an instant solution, then i will embed some codes to my pic software and i will use asm codes with my bcb.Anyway, if you see something suits me, just ring.
:=Thanks.
:=
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10609
No_Fear
Guest







Re: Ciphering again
PostPosted: Sat Jan 11, 2003 12:22 pm     Reply with quote

Thanks i will try it Smile)
:=<font face="Courier New" size=-1>You just have to locate the TEA algorithm in C if you want to compile it for the PC.
:=
:=Here it is:
:=
:=/************************************************
:=
:=The Tiny Encryption Algorithm (TEA) by
:=David Wheeler and Roger Needham of the
:=Cambridge Computer Laboratory
:=
:=**** ANSI C VERSION ****
:=
:=Notes:
:=
:=TEA is a Feistel cipher with XOR and
:=and addition as the non-linear mixing
:=functions.
:=
:=Takes 64 bits of data in v[0] and v[1].
:=Returns 64 bits of data in w[0] and w[1].
:=Takes 128 bits of key in k[0] - k[3].
:=
:=TEA can be operated in any of the modes
:=of DES. Cipher Block Chaining is, for example,
:=simple to implement.
:=
:=n is the number of iterations. 32 is ample,
:=16 is sufficient, as few as eight may be OK.
:=The algorithm achieves good dispersion after
:=six iterations. The iteration count can be
:=made variable if required.
:=
:=Note this is optimised for 32-bit CPUs with
:=fast shift capabilities. It can very easily
:=be ported to assembly language on most CPUs.
:=
:=delta is chosen to be the real part of (the
:=golden ratio Sqrt(5/4) - 1/2 ~ 0.618034
:=multiplied by 2^32).
:=
:=************************************************/
:=
:=void encipher(unsigned long *const v,unsigned long *const w,
:=const unsigned long *const k)
:={
:= register unsigned long y=v[0],z=v[1],sum=0,delta=0x9E3779B9,
:= a=k[0],b=k[1],c=k[2],d=k[3],n=32;
:=
:= while(n-->0)
:= {
:= sum += delta;
:= y += (z<<4)+a ^ z+sum ^ (z>>5)+b;
:= z += (y<<4)+c ^ y+sum ^ (y>>5)+d;
:= }
:=
:= w[0]=y; w[1]=z;
:=}
:=
:=void decipher(unsigned long *const v,unsigned long *const w,
:=const unsigned long *const k)
:={
:= register unsigned long y=v[0],z=v[1],sum=0xC6EF3720,
:= delta=0x9E3779B9,a=k[0],b=k[1],c=k[2],
:= d=k[3],n=32;
:=
:= /* sum = delta<<5, in general sum = delta * n */
:=
:= while(n-->0)
:= {
:= z -= (y<<4)+c ^ y+sum ^ (y>>5)+d;
:= y -= (z<<4)+a ^ z+sum ^ (z>>5)+b;
:= sum -= delta;
:= }
:=
:= w[0]=y; w[1]=z;
:=}
:=
:=// end of TEA algorithm
:=
:=Here's a link where you can find the above source:
:=
:= <a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank"> <a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank"> <a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank"> <a href="http://vader.brad.ac.uk/tea/tea.shtml" TARGET="_blank">http://vader.brad.ac.uk/tea/tea.shtml</a></a></a></a>
:=
:=I hope that helps. (I'll probably use a cipher in a product soon, so I've been collecting info on them)
:=
:=Mark
:=
:=
:=
:=
:=
:=
:=:=Thanks for all reply.Yea, i agree with you i must embed the code but i will encode some data with my pic and decrypt it back with my program which i am writing with borland c++ builder.And most of the trouble is, when i use some asm codes in bcb i got lots of trouble with it.I mean i want to use encryption/decryption algorithm both pic and bcb.If i can't find an instant solution, then i will embed some codes to my pic software and i will use asm codes with my bcb.Anyway, if you see something suits me, just ring.
:=:=Thanks.
:=:=
:=</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 10617
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group