473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help with "AES Encryption Algorithm for VBA and VBScript"

zmbd
5,501 Expert Mod 4TB
Re: AES Encryption Algorithm for VBA and VBScript.

Hello,
Trying to step thru this code...

After reading thru the code, I tried to compile it

The following errors occur in the VBA module:
- "Set oFile1 = oFS.OpenTextFile(sFile, ForReading)" I get the error "ForReading" isn't a defined variable.
- "expandedKey = expandKey(aesKey, sbox, rcon)" as an undefined sub/function.

The first error I was able to work around using "OPEN" etc...
The second error, I'm not entirely sure about how to fix.

-z
May 14 '12 #1

✓ answered by Rabbit

Glad you got it working. I tested against a handful of NIST values but I wasn't exhaustive in my tests. Let me know if you find any errors.

Just be aware that my code was more optimized for speed than for readability. So rather than encapsulating the transformations in their own function, I expanded everything and put most of it in one function to avoid the overhead.

6 9793
NeoPa
32,556 Expert Mod 16PB
When I look at the first block of code I see that expandKey() is defined on line #387.
Expand|Select|Wrap|Line Numbers
  1. Function expandKey(ByRef key(), ByRef box(), ByRef rcon())
Maybe you had a problem copying it all completely.

ForReading is a constant with a value of 1. ForWriting is a constant with a value of 2. See more at TechNet - Reading and Writing Text Files. If these constants aren't already defined for you then I suspect you may not have all the correct references set. Alternatively, you can set them up yourself or use the literal values.
May 14 '12 #2
zmbd
5,501 Expert Mod 4TB
THANK YOU!!!

I'd never used this method to open a textfile for output.
In the past I'd used "Freefile", "Open", "Print", and "Close."
After reading up on the code I found where the references were missing from the "ForReading" "ForWriting", even found a bit of example code; however, the "ForAppend" was set to 3 not 8 which burggered me for awhile.

I'll try that cut and paste again!
I've been working from a textbook to create an AES function in VBA and here it is!!!!!!!!!

SO COOL!

-z

PS:
NeoPa:
Went back to the code... this is what I see when the the code is expanded:


Also, for some reason... all I see from the code you posted is the function header... no code.

What am I doing wrong?

-z
Attached Images
File Type: jpg AES_Code_PrtScn.jpg (22.6 KB, 4512 views)
May 14 '12 #3
Rabbit
12,516 Expert Mod 8TB
zmbd, NeoPa only posted the header to show that the function was indeed defined in the code. What he was saying is that if you're getting the error, perhaps something went wrong when you copied and pasted the code from the site.
May 14 '12 #4
NeoPa
32,556 Expert Mod 16PB
@zmbd
Your picture is of the code at the bottom of the second block of code. My reference was to the first block ;-)
NeoPa:
When I look at the first block of code I see that expandKey() is defined on line #387.
May 14 '12 #5
zmbd
5,501 Expert Mod 4TB
Rabbit,
1ST - Thank You for the code!!

Indeed the function is in the ECM-Code-Block; however, I had originally copied the code from the following CBC-Code-Block.

Thus, to have something to work thru, I copied the code from the ECM-Code-Block, made a few tweeks:
- added "()" in the DIM sections for array variables;
- changed a "ByVal" to "ByRef" as required for array;
- added CONST for "forwrite" and "forread";
- change oWP.Value to sPass for the passphrase and added an "sPassIn" to the call (figured oWP is a textbox on a form which is what I would do))

After that the VBA compiler was happy and the code ran as expected.

So I started comparing the ECM-Mode code to the posted CBC code... some of the same tweeks as above needed to be made for the CBC code to compile and I had to C&P the expandkey() from the ECM code into the copied CBC code. It now will compile and encyphr the selected text file.

I haven't looked thru the expandkey() nor used the NIST files to verify.

Once again,
Thank You Rabbit!

I had finished creating the arrays and started trying to understand how to implement the equations... the text I am using is heavy on the theory and not so much on the practical application, and then, WOW, your code showed up! What a help in trying to follow the textbook!

-Z
May 14 '12 #6
Rabbit
12,516 Expert Mod 8TB
Glad you got it working. I tested against a handful of NIST values but I wasn't exhaustive in my tests. Let me know if you find any errors.

Just be aware that my code was more optimized for speed than for readability. So rather than encapsulating the transformations in their own function, I expanded everything and put most of it in one function to avoid the overhead.
May 14 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
4
by: Kinsley Turner | last post by:
Hey-ho, I'm getting a bit out of my depth porting the 'tiny encryption algorithm' from C to python. Ref: http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm...
15
by: Optimus | last post by:
I would like to know if there is a encryption algorithm that returns only lowercase encrypted string. Thanks in advance.
3
by: Dave Cullen | last post by:
Hello C I have a project that requires a calculated "key" to be used in a security access application. The customer supplies a secret 8 byte number that gets combined with the serial number of...
2
by: thiyagu | last post by:
In our company for internal security compliance we need to encrypt the data to/from DB server; What is the encryption algorithm used by DB2 & what key lengths are supported in DB2 LUW v8 & v9 when...
9
Rabbit
by: Rabbit | last post by:
Introduction The Advanced Encryption Standard is the algorithm that won the National Insitute of Standards and Technology's (NIST) search for a standardized encryption algorithm in 2001. In 2002, it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.