- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I needed to do some simple encryption work and found, on the Web, the answer to my problem in Wheeler & Needham's Tiny Encryption Algorithm. The only problem was that it was written in C, which I really don't understand very well - C seems ironically appropriate for writing an encryption algorithm. All attempts to find a Fortran version failed, the best I could do was find a version written in Java. So I did the hard work and wrote it in Fortran. I post it here in case anyone else needs it ...
subroutine encrypt(num,k1,k2,k3,k4)
implicit none
integer*8num,sum,delta,number
integer*4n(2),k1,k2,k3,k4,n1,n2,i
equivalence(number,n)
!***********************************************************
number = num
delta = 2654435769
sum = 0
sum = 0
n1 = n(1)
n2 = n(2)
n2 = n(2)
do i = 1,32
sum = sum + delta
n1 = n1 + xor(xor(isha(n2,4)+k1,n2+sum),isha(n2,-5)+k2)
n2 = n2 + xor(xor(isha(n1,4)+k3,n1+sum),isha(n1,-5)+k4)
end do
sum = sum + delta
n1 = n1 + xor(xor(isha(n2,4)+k1,n2+sum),isha(n2,-5)+k2)
n2 = n2 + xor(xor(isha(n1,4)+k3,n1+sum),isha(n1,-5)+k4)
end do
n(1) = n1
n(2) = n2
n(2) = n2
num = number
return
end
!!
subroutine decrypt(num,k1,k2,k3,k4)
return
end
!!
subroutine decrypt(num,k1,k2,k3,k4)
implicit none
integer*8num,sum,delta,number
integer*4n(2),k1,k2,k3,k4,n1,n2,i
equivalence(number,n)
!***********************************************************
number = num
delta = 2654435769
sum = 3337565984
sum = 3337565984
n1 = n(1)
n2 = n(2)
n2 = n(2)
do i = 1,32
n2 = n2 - xor(xor(isha(n1,4)+k3,n1+sum),isha(n1,-5)+k4)
n1 = n1 - xor(xor(isha(n2,4)+k1,n2+sum),isha(n2,-5)+k2)
sum = sum - delta
end do
n2 = n2 - xor(xor(isha(n1,4)+k3,n1+sum),isha(n1,-5)+k4)
n1 = n1 - xor(xor(isha(n2,4)+k1,n2+sum),isha(n2,-5)+k2)
sum = sum - delta
end do
n(1) = n1
n(2) = n2
n(2) = n2
num = number
return
end
return
end
Links to the original paper and others, complete with theory, can be found at http://www.simonshepherd.supanet.com/tea.htm
In my version, num is an integer of up to 20 digits which is returned encrypted. The values k1,k2,k3,k4 are random integers (I used 9 digit integers) which must be the same for both encrypt and decrypt. I confess I don't understand the significance of the particular values for delta and sum as used in the original paper.
I'd be glad to hear of any comments or criticism.
Good luck
Mike
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not an expert in encryption, but many years ago I found a similar algorithm and wrote routines for it. It was pointed out to me that the algorithm wasn't very good, as encryption goes. Of course, it all depends on your needs - simple encryption for the purpose of making it annoyingly difficult for most people to gain unauthorized access may well be sufficient. I put something like this into the evaluation license code for CVF.
There is a CRYPTO sample in CVF 6.6, which also works in Intel Fortran. It is based on an MSDN sample and uses Windows' encryption services. Probably overkill for you. See ftp://ftp.compaq.com/pub/products/fortran/vf/supp/crypto.zip
There is a CRYPTO sample in CVF 6.6, which also works in Intel Fortran. It is based on an MSDN sample and uses Windows' encryption services. Probably overkill for you. See ftp://ftp.compaq.com/pub/products/fortran/vf/supp/crypto.zip

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page