473,467 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

AES encryption

I have just finished a new function that will do AES128 encryption,
which is the standard for private-key cryptology today. In fact, the
NSA permitted AES to be used for classified documents in the USA, the
first time a public algorithm has been given this honor (Secret and Top
Secret documents can use AES as well, but must use a larger key (192 or
256 bits)) I've tested my function with a thousand random texts, it
seems to return the same result as received every time.

If you want to take a look,
http://www.geocities.com/brp13/Python/index.html

Note, I still wouldn't quite encrypt your credit card numbers, but,
well, it does seem to be secure enough... I would like comments as to
anything fairly simple I might be able to do to increase security. I've
tested the algorithm about a thousand times, with no appearant
failures, but, there still could be one that I haven't found yet, so...
Thanks!

Mar 7 '06 #1
5 1539
Tuvas wrote:
[...]
I've tested my function with a thousand random texts, it
seems to return the same result as received every time.


Unfortunately, the results seem incorrect, self-consistent
as they may be. The following will call your code, and
check the results against 3 popular test vectors.

--Bryan
# Assert false if test fails

test_key = (
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
0x76, 0x2e, 0x71, 0x60, 0xf3, 0x8b, 0x4d, 0xa5,
0x6a, 0x78, 0x4d, 0x90, 0x45, 0x19, 0x0c, 0xfe)

test_plaintext = (
0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d,
0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34)

expected = (
(0x39, 0x25, 0x84, 0x1d, 0x02, 0xdc, 0x09, 0xfb,
0xdc, 0x11, 0x85, 0x97, 0x19, 0x6a, 0x0b, 0x32),

(0xf9, 0xfb, 0x29, 0xae, 0xfc, 0x38, 0x4a, 0x25,
0x03, 0x40, 0xd8, 0x33, 0xb8, 0x7e, 0xbc, 0x00),

(0x1a, 0x6e, 0x6c, 0x2c, 0x66, 0x2e, 0x7d, 0xa6,
0x50, 0x1f, 0xfb, 0x62, 0xbc, 0x9e, 0x93, 0xf3))

key_sizes = (16, 24, 32)
plaintext = s2num(''.join([chr(c) for c in test_plaintext]))
for i in range(len(key_sizes)):
key_size = key_sizes[i]
key = s2num(''.join([chr(c) for c in test_key[:key_size]]))
expected = s2num(''.join([chr(c) for c in expected[i]]))
ciphertext = encryptb(plaintext, key)
assert ciphertext == expected
deciphertext = decryptb(ciphertext, key)
assert deciphertext == plaintext

Mar 7 '06 #2
I don't know if it means anything, but the AES system that I have isn't
set up to do anything other than 128 bit encryption at the moment, nor
will it likely do so, mainly because most systems only explain how to
get the 128 encryption, and not the larger sizes. I'm sure it's fairly
easy to change, but... Well, I'll take a look at it, but I don't have
the time at the moment...

Mar 7 '06 #3
Okay, I figured out the problem. The problem was that my algorythm
filed the numbers into the matrix as so:
1 2 3 4
5 6 7 8...

While it should have been
1 5 9 13
2 6 10 14
....

When this was fixed, the program works great! That's what I get for
testing only asymetrical keys... Oh well, thanks for the help in fixing
the problem!

Mar 8 '06 #4
Ere, I mean testing only symetrical keys, and symetrical messages,
nothing more realistic. Sigh. Oh well. It works, and that's the
important thing. I don't know if I'll put in support for the larger key
sizes, but, I'll leave it be for now.

Mar 8 '06 #5
I wrote:
Tuvas wrote:
[...]
I've tested my function with a thousand random texts, it
seems to return the same result as received every time.

Unfortunately, the results seem incorrect, self-consistent
as they may be. The following will call your code, and
check the results against 3 popular test vectors.

--Bryan
# Assert false if test fails

test_key = (
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
0x76, 0x2e, 0x71, 0x60, 0xf3, 0x8b, 0x4d, 0xa5,
0x6a, 0x78, 0x4d, 0x90, 0x45, 0x19, 0x0c, 0xfe)

test_plaintext = (
0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d,
0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34)

expected = (
(0x39, 0x25, 0x84, 0x1d, 0x02, 0xdc, 0x09, 0xfb,
0xdc, 0x11, 0x85, 0x97, 0x19, 0x6a, 0x0b, 0x32),

(0xf9, 0xfb, 0x29, 0xae, 0xfc, 0x38, 0x4a, 0x25,
0x03, 0x40, 0xd8, 0x33, 0xb8, 0x7e, 0xbc, 0x00),

(0x1a, 0x6e, 0x6c, 0x2c, 0x66, 0x2e, 0x7d, 0xa6,
0x50, 0x1f, 0xfb, 0x62, 0xbc, 0x9e, 0x93, 0xf3))

key_sizes = (16, 24, 32)
plaintext = s2num(''.join([chr(c) for c in test_plaintext]))
for i in range(len(key_sizes)):
key_size = key_sizes[i]
key = s2num(''.join([chr(c) for c in test_key[:key_size]]))
expected = s2num(''.join([chr(c) for c in expected[i]]))
ciphertext = encryptb(plaintext, key)
assert ciphertext == expected
deciphertext = decryptb(ciphertext, key)
assert deciphertext == plaintext


Oops, introduced a bug by shadowing "expected". Make the for loop:

for i in range(len(key_sizes)):
key_size = key_sizes[i]
key = s2num(''.join([chr(c) for c in test_key[:key_size]]))
expect = s2num(''.join([chr(c) for c in expected[i]]))
ciphertext = encryptb(plaintext, key)
assert ciphertext == expect
deciphertext = decryptb(ciphertext, key)
assert deciphertext == plaintext
--
--Bryan
Mar 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cliff | last post by:
We are trying to connect to 3 different Oracle databases using MS Access as the front-end and ODBC as the connection. The problem that we are having is that 1 of the databases requires a...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
7
by: Alan Silver | last post by:
Hello, I am writing a page where sensitive data is collected (over SSL) and stored in a database. I have been looking at the .NET encryption classes, but am a bit confused as to which is best...
2
by: Sumit Gupta | last post by:
Can anyone please tell me how to encrpt string or any kind of Data. Also the Algorithm of Compression. Any Link tutorial etc. Like : Zip or RAR Formats etc.
9
by: sweety | last post by:
Dear All, How to encrypt a C data file and make binary file and then have to read a bin file at run time and decrypt the file and have to read the data. Any help to achive this pls. Would be...
4
by: pintu | last post by:
Hello everybody.. I hav some confusion regarding asymmetric encryption.As asymmetric encryption it there is one private key and one public key.So any data is encrypted using private key and the...
1
by: =?Utf-8?B?bWljcm9ob2Y=?= | last post by:
Short version: Is there a way to configure (preferably programmatically) the max encryption strength that will be used by the framework when connecting to a particular SSL-protected web service? ...
11
by: John Williams | last post by:
I've written a simple program to do XOR encryption as my first foray into understanding how encryption works. The code compiles fine, however it segmentation faults on every run. using gdb to...
22
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.