Security
  Home arrow Security arrow Page 4 - An Introduction to Cryptography
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SECURITY

An Introduction to Cryptography
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-07-23

    Table of Contents:
  • An Introduction to Cryptography
  • The Study of Cryptography
  • First Example: Byte Adder Algorithm
  • Second Example: Variation of the Byte-Adder

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    An Introduction to Cryptography - Second Example: Variation of the Byte-Adder
    (Page 4 of 4 )

    The main idea of this algorithm is the same as that of the aforementioned Byte-Adder. However, instead of adding/subtracting a user-specified numeric value we will generate, via a quick mathematical formula, an integer from the user-specified string. Therefore, we will work again with two text files and a character string that stands for the password.

    Here's the algorithm: (in this case— ‘-' for encryption or ‘+' for decryption)

    for (int i=0;i<len;i++)

       total += pw[i];

    c -= pw[len-1]*(total / len);

    Variables: "len" stands for the length of the password; "pw" represents the given password string; and "c" will be the newly generated byte as we pass through the content of the file.

    For the exact same input text file check out the generated output:

     Í ÍÍ!%!ÍÍ­Í! !Í"­  ÛÍõÍ&"Í&η·ñ#­Í ÛÍ !ÙÍ! !ÙÍ! !ÛÍ   ÛÍÞßàáâãäåæ

    The password was: "longpassword123" in the above example.

    Now, let's see the complete program:

    #include <fstream.h>        //or <fstream> and ‘using namespace std;'

    #include <stdio.h>

    #include <string.h>

    char srcfile[30], dstfile[30], pw[30];

    void main()

    {

       printf("Source file: "); scanf("%s",srcfile);

       printf("nDestination file: "); scanf("%s",dstfile);

       printf("nPassword: "); scanf("%s",pw);

       printf("nPress 1.> if Encryption or 2.> if Decryption: ");

       int opt; char c;

       scanf("%d",&opt);

       int total=0; int len=strlen(pw);

       for (int i=0;i<len;i++)

           total += pw[i];

       ifstream s(srcfile);

       ofstream d(dstfile);

       if (!s || !d)

           printf("nERROR: Couldn't open one of the files!");

       while (s.get(c))

       {

           if (opt==1)

              d << c - pw[len-1]*(total / len);

           else

              d << c + pw[len-1]*(total / len); 

       }

       s.close();  d.close();

       printf("nAll done.");

    }

    You can download its compiled version in executable format and also the source by clicking on the archive button below. It is archived in RAR. It's in working condition.

    I have purposefully reduced the complexity of these algorithms to make them "obviously simple," easy and comprehensible for a beginner too. My intention with this introductory article was to familiarize you, the reader, with encryption algorithms rather than writing about top-notch algorithms. I am aware that there are zillions of other variations of the aforementioned algorithms and different ways to code it — more efficiently, more secure, etc. — but for now, our top priority was to understand what cryptography is all about.

    Conclusions

    I've shown you two possible de/encryptions. You should be able to use this mindset and work out a few variations of your own, too. Just use your imagination. It's that simple. Play with encryption. That's the beauty of it — you can actually see your results! You encrypt it… you get gibberish. You decrypt it… you get the original file.  It works!

    Jokes aside, unfortunately, I am running out of space right now. However, be sure to stick around for the second part of this series. There I will show you one of the most popular encryption algorithms. It's the XOR. Yes, we will XOR.

    In the next part I will also explain three unique ways to break an XOR-based encryption. None of those are secret but very few users actually grab a book to do the research to find out how. Obviously, use them just for educational purposes.

    And to whet your appetite... there will be a third part to this series too! In that article I will talk about security and reliability. I will show you some of the top-notch encryption algorithms and security solutions that currently dominate the cryptographic landscape. I will also spark some of your hidden desires toward this and motivate you to read some of the best literature that's available on this topic. Expect to see an awesome compilation of further reading and references.

    Until then -- keep coding, learning, reading and researching. See you at part two!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · I hope that you've enjoyed this introduction into cryptography. Be prepared for the...
     

       

    SECURITY ARTICLES

    - An Epilogue to Cryptography
    - A Sequel to Cryptography
    - An Introduction to Cryptography
    - Security Overview
    - Network Security Assessment
    - Firewalls
    - What’s behind the curtain? Part II
    - What’s behind the curtain? Part I
    - Vectors
    - PKI: Looking at the Risks
    - A Quick Look at Cross Site Scripting
    - PKI Architectures: How to Choose One
    - Trust, Access Control, and Rights for Web Se...
    - Basic Concepts of Web Services Security
    - Safeguarding the Identity and Integrity of X...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway