Security
  Home arrow Security arrow Page 4 - An Introduction to Cryptography
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
SECURITY

An Introduction to Cryptography
By: Barzan "Tony" Antal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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!



     
     
    >>> More Security Articles          >>> More By Barzan "Tony" Antal
     

       

    SECURITY ARTICLES

    - Critical Microsoft Visual Studio Security Pa...
    - US Faces Tech Security Expert Deficit
    - LAN Reconnaissance
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek