Adblock breaks this site

My cryptography function.

Discussion in 'Programming General' started by -------owned-------, Oct 23, 2008.

  1. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    My cryptography function.

    Yes, guys, I know it's newbie-stuff, I do NOT need any feedback. Thank you.
    I just can't figure a way to reverse it.
    Can anyone help? ^_^
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <string.h>
    /* Integers */
    int charPos;
    int plainlen;
    int x = 0;
    int a = 0;
    int b = 0;
    int random;
    int i;
    int y = 0;
    int random1 = 0;
    int z = 0;
    int declen;
    /* Character arrays (strings) */
    char plaintext[100];
    char encryptedtext[100];
    /* Methods */
    void encipher(char plain[]);
    void decipher(char enc[]);
    int string_length(char str[]);
    /* End */
    
    char block[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789!#¤%&/()=?";
    char input[100];
    int main(char* argv[]) {
        scanf ("%s",&plaintext) ;
        i = string_length(plaintext);
        encipher(plaintext);
        decipher(plaintext);
    }
    int string_length(char* plaintext) {
     return strlen(plaintext);
    }
    void encipher(char plain[]) {
           srand ( time(NULL) );
    
                       while(x < i) {
    
                                                           while(y < 8) {
    
                                                                  while(z < 7) {
                                                                            random1 = rand() % 67 + 1;
                                                                   printf("%c",block[random1]);
                                                                                 z++;}  
                                                                                  z = 0;            printf("%c",plaintext[x]);
                                                                   y++;
                                                                         x++;
                                                                   }
                                                             
                                                                   }
                                 
         }
    void decipher(char enc[]) {
         declen = string_length(enc);
         plainlen = declen / 8;
           while(a < plainlen) {
                   b = b + 8;
                   printf("%c",enc[b]);
                   }
                  return;
                  }
    
     
  2. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    My cryptography function.

    You can't reverse it since you've used the random number generator in part of the encryption.
     
  3. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    My cryptography function.

    Why can't I?
    It's pretty much 1 character, then eight other (was it seven?).
    I can reverse it manually when I see it.
     
  4. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    My cryptography function.

    if you use rand(), there is no way to tell what the number is once the string is encrypted, unless you keep a cache which is extremely insecure and inefficient.
     
  5. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    My cryptography function.

    Can't I just split the string in pieces or something?
    Rand() is for determining which characters the next seven will be.
     
  6. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    My cryptography function.

    If I'm understanding you correctly, this is a rather insecure way of doing things ...
     
  7. -------owned-------

    -------owned------- Guru
    Banned

    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0
    My cryptography function.

    Indeed it is, I'm just trying out some new functions etc.
    I'm new to C.
     
  8. DreaDz

    DreaDz Member

    Joined:
    Dec 13, 2008
    Posts:
    62
    Referrals:
    0
    Sythe Gold:
    0
    My cryptography function.

    Use keys, not just a random number gen.
     
  9. TheAlchemist

    TheAlchemist Newcomer

    Joined:
    Feb 18, 2009
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0
    My cryptography function.

    If you want to waste about 100+ lines of code you could program an algorithm that calculates the number, you have to remember, not even computers are truly random..

    Or

    ..Not sure, i havnt programmed in C++ in a lot of years, but i would suggest having a brute forcer that locks out after 10 attempts. That way it has to guess the number and only the one number can be bruted.. In all honesty, unless your doing it for practice this kind of cryptography is pretty much useless.
     
< HELP is needed. | Need help with fixing my script! >


 
 
Adblock breaks this site