Thread: Encryption In C

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    104

    Encryption In C

    Speaking of which, how do I go about making my own encryption in C for ascii and bin files?

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    5
    Start off with XOR encryption.

    pseudo code:
    Code:
    string key = "monkey"
    string encryptme = "secretcode"
    string final
    int keylength = strlen(key)
    int keypos = 0
    
    for (i = 0; encryptme[i] != '\0'; i++) {
    	final[i] = encryptme[i] ^ key[keypos]
    	keypos ++
    	if (keypos > keylength) {	
    		keypos = 0
    	}
    }
    or something like that.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    104
    What is XOR?

    I think just giving me a basic (general) english algorithm has to how I should go about making one would help me alot more.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User grady's Avatar
    Join Date
    Oct 2003
    Posts
    27
    Choose 2 large primes p and q
    pick e>1 such that gcd(e,(p-1)(q-1))=1
    Let n=pq
    encoded symbol M as C=M^e mod n
    solve ed=1 mod (p-1)(q-1) for d
    Decode coded symbol C as M=C^d mod n

    e and n are publicly announced so anyone can encode a message. All the other numbers are to be kept secret. p and q need to be 200+ digits if you're doing this for real life use. Google: RSA encryption, Fermat's little theorem, modular arithmetic, greatest common divisor algorithm, arbitrary precision arithmetic. books: abstract algebra.
    Last edited by grady; 12-22-2003 at 01:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. help needed with edit control & encryption
    By willc0de4food in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2006, 08:21 PM
  3. abt encryption algorithm
    By purIn in forum C Programming
    Replies: 9
    Last Post: 12-22-2003, 10:16 PM
  4. What's wrong with my Stream Cipher Encryption?
    By Davros in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2002, 09:51 PM
  5. File Encryption & Read/Write in Binary Mode
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 06:45 PM