Hello,
I'm a newcomer to the world of computer programming. Although I already have a relatively good understanding of C, I'm really lost trying to create a simple program, using the Win32 API, in which I could encrypt a plain text file and also to decrypt the same text file in another computer which have the same program installed. I already searched all MSDN topics and articles and none could give a subtle introduction to the topic. All of them assumes that you are already well versed in cryptography.
I would like that my program load a text file and then the client has two buttons, one to encrypt and another d decrypt. Can anyone shed some light on how I could do this? I already know how to program the window with the menus, buttons and even an "about" dialog, but I'm really lost on how to implement the Crypto API on a program.
If anyone could give me some hints I would really appreciate.
Tnx in advance!
3 replies to this topic
#1
Posted 08 November 2011 - 05:30 AM
|
|
|
#2
Posted 13 November 2011 - 07:49 AM
I don't know if there is a library or effective method to encrypt files, however there is one very simple method I used earlier for ciphering and deciphering plain text files to protect them.
What I did was to generate random "key" integer each time I run my application; ( when a client connects to server, client uses server's key value if you have implemented socket programming ) , and increased ASCII character value of each character in the text by that integer. Of course that key number should be reasonable integer.
For instance, PEN has ASCII code of 82,69,77 . P = "82" , E = "69" , N="77".
To encrypt this text, I used that key value to increase each character by , lets say 5 , then the characters would be 87,74,82 which is "WJR". To Decipher it, you should substract key value ofcourse.
If you are generating random key everytime, and you use the application only one time ( without connecting two machines with same application running ) then things get a little bit complex but I can explain how it works if you are interested.
I know this is very trivial , but since you are not sending key value along with the data; someone who doesn't know the key integer and who doesn't know basics about cryptography would still have hard time solving what is written in the text.
I hope I understood the question properly and hope I have been helpful.
Good-luck.
What I did was to generate random "key" integer each time I run my application; ( when a client connects to server, client uses server's key value if you have implemented socket programming ) , and increased ASCII character value of each character in the text by that integer. Of course that key number should be reasonable integer.
For instance, PEN has ASCII code of 82,69,77 . P = "82" , E = "69" , N="77".
To encrypt this text, I used that key value to increase each character by , lets say 5 , then the characters would be 87,74,82 which is "WJR". To Decipher it, you should substract key value ofcourse.
If you are generating random key everytime, and you use the application only one time ( without connecting two machines with same application running ) then things get a little bit complex but I can explain how it works if you are interested.
I know this is very trivial , but since you are not sending key value along with the data; someone who doesn't know the key integer and who doesn't know basics about cryptography would still have hard time solving what is written in the text.
I hope I understood the question properly and hope I have been helpful.
Good-luck.
#3
Posted 13 November 2011 - 10:11 AM
HI! Good to think and code some realistic programs. :)
Well! For encryption and decryption you are not bound to use the win32 API. Encryption means that to change the form of data or information to code (code language -- which wouldn't be understandable). So, the form into which you are encrypting your data shall be determined by you. To encrypt, the data will be processed through certain steps or mechanism which is normally called an Algorithm. For every encryption you can write a different algorithm. The algorithm might be somehow like, add the current digit by 27 or change the current alphabet with the next or previous or nth one and multiply, divide and do such and such. Well, your algorithm must be in sequence for the same data -- it should be same. While in decryption we reverse the algorithm like, if we added 27 to the current digit then subtract it and same procedure with other things we applied. In short, in decryption we rollback our data.
For a larger application, if the data is to be send and received -- the data can be simply encrypted or decrypted. But for security purpose you can include a key also in your encryption -- if the receiver provides the correct key then data will be decrypted.
To be a single command-line program, this is enought. But if you want to make it GUI, it's a lot easier and so harder :). Well, if you know GUI programming, it will be easier for you -- if you don't then you have to learn it totally first and then create your application. You can't create your application by just learning how to create a button and an editbox -- you have to learn it from A-Z. My advise is to create it a console application first so you will keep your attention on the purpose of your program rather than messing with GUI.
About the GUI, you have many options to create a GUI program. But to your point -- if you are willing to create your GUI program using win32 API then it might be in difficult mode. A good place to start learning is to go here. If you want an easier way then you have to select MFC -- get VC++ 6 and learn GUI programming with MFC. It is much easier and fast to learn.
If you have anything to ask now or then you are Welcomed!
Hope this helps!
Well! For encryption and decryption you are not bound to use the win32 API. Encryption means that to change the form of data or information to code (code language -- which wouldn't be understandable). So, the form into which you are encrypting your data shall be determined by you. To encrypt, the data will be processed through certain steps or mechanism which is normally called an Algorithm. For every encryption you can write a different algorithm. The algorithm might be somehow like, add the current digit by 27 or change the current alphabet with the next or previous or nth one and multiply, divide and do such and such. Well, your algorithm must be in sequence for the same data -- it should be same. While in decryption we reverse the algorithm like, if we added 27 to the current digit then subtract it and same procedure with other things we applied. In short, in decryption we rollback our data.
For a larger application, if the data is to be send and received -- the data can be simply encrypted or decrypted. But for security purpose you can include a key also in your encryption -- if the receiver provides the correct key then data will be decrypted.
To be a single command-line program, this is enought. But if you want to make it GUI, it's a lot easier and so harder :). Well, if you know GUI programming, it will be easier for you -- if you don't then you have to learn it totally first and then create your application. You can't create your application by just learning how to create a button and an editbox -- you have to learn it from A-Z. My advise is to create it a console application first so you will keep your attention on the purpose of your program rather than messing with GUI.
About the GUI, you have many options to create a GUI program. But to your point -- if you are willing to create your GUI program using win32 API then it might be in difficult mode. A good place to start learning is to go here. If you want an easier way then you have to select MFC -- get VC++ 6 and learn GUI programming with MFC. It is much easier and fast to learn.
If you have anything to ask now or then you are Welcomed!
Hope this helps!
I think i'm able to write a code for printing "Hello, World!". Proud of that!
#4
Posted 13 November 2011 - 04:19 PM
I doubt Windows API has any encryption functions, since this is not really an OS specific thing. You can easily encrypt data with some basic methods, such as the mentioned ASCII math, bit-wise operations (and, or, xor, not, etc). For more advanced levels you use a combinations of those and many others out there.
Also, note that a lot of basic cryptography can be broken with a simple frequency analysis.
For quick start with GUI I'd recommend Visual C++, or Qt as a nice alternative. On socket programming, there are many tutorials, so you can build your own class, or use networking from other libraries, such as Qt, SDL, SFML, boost and I think MFC has that one too.
Also, note that a lot of basic cryptography can be broken with a simple frequency analysis.
For quick start with GUI I'd recommend Visual C++, or Qt as a nice alternative. On socket programming, there are many tutorials, so you can build your own class, or use networking from other libraries, such as Qt, SDL, SFML, boost and I think MFC has that one too.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









