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 DougGuest

Re: Ciphering again

Posted: Fri Jan 10, 2003 1:48 pm

:=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 DSylvaGuest

Re: Ciphering again

Posted: Fri Jan 10, 2003 2:29 pm

:=:=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_FearGuest

Re: Ciphering again

Posted: Fri Jan 10, 2003 5:26 pm

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 DSylvaGuest

Re: Ciphering again

Posted: Fri Jan 10, 2003 9:01 pm

<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.

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).

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_FearGuest

Re: Ciphering again

Posted: Sat Jan 11, 2003 12:22 pm

Thanks i will try it )
:=<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