Thread: Need Help in C!!

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    2

    Need Help in C!!

    i want to write some basic security code by user key in 1 sentence with 5 alphabet
    like "Human" and insert generate key = 2.

    Word = "human"
    generateKey ="2"
    then my output want be :
    h--> j
    u--> w
    m-->o
    a--> c
    n--> p

    out >> jwocp ..forward the aplhabet with 2(generateKey)

    so, it is in C language got function 2 can fast forward the alphabet?
    if not can suggest how 2 solve this problem. Thank You

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    there is no any fucntion to do this. but u can write a small fucntion which could achive this problem. the basic idea is as follow

    [h] [e] [l] [l] [o] [\0] <-- think this is string which u wanted to encrypt it

    the first thing u wanted to do is read the first char, get the ASCII value of that char incremnet the ASCII vlaue of that char by 2 you move two char forwad,
    Code:
    char str[]="hello";
    
    str[0] = str[0] + 2; // 104 + 2 = 106 -->'j'
    and if u want to deencrypt it the other way round read each char and -2 with each char ASCII value

    hope u got the idea

    ssharish2005

  3. #3
    Registered User
    Join Date
    Feb 2006
    Location
    Chennai, India
    Posts
    3
    Quote Originally Posted by s3ng
    i want to write some basic security code by user key in 1 sentence with 5 alphabet
    like "Human" and insert generate key = 2.

    Word = "human"
    generateKey ="2"
    then my output want be :
    h--> j
    u--> w
    m-->o
    a--> c
    n--> p

    out >> jwocp ..forward the aplhabet with 2(generateKey)

    so, it is in C language got function 2 can fast forward the alphabet?
    if not can suggest how 2 solve this problem. Thank You
    #define KEY 2

    char str[]="human";
    //make a loop for no of iteration=no of character in the given string,and increment each char with encryption key.
    store the result in new string.This is your encrypted string.
    str_new[0] = str[0] + 2; // char incremented by key (2)

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    selva I liked how you defined a keyword and never used it. Also, it's not in the habit of this forum to post basically the exact same code someone else replied with a day earlier.

    ...and to the OP. If you're really looking into security measures, you should look into bitwise operators.
    Last edited by SlyMaelstrom; 02-23-2006 at 01:14 PM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed