My cryptography function.

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

My cryptography function.
  1. Unread #1 - Oct 23, 2008 at 2:03 PM
  2. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    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;
                  }
    
     
  3. Unread #2 - Oct 23, 2008 at 10:46 PM
  4. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    My cryptography function.

    You can't reverse it since you've used the random number generator in part of the encryption.
     
  5. Unread #3 - Oct 24, 2008 at 12:46 AM
  6. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    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.
     
  7. Unread #4 - Oct 24, 2008 at 2:16 AM
  8. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    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.
     
  9. Unread #5 - Oct 27, 2008 at 12:59 PM
  10. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    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.
     
  11. Unread #6 - Oct 28, 2008 at 2:36 AM
  12. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    My cryptography function.

    If I'm understanding you correctly, this is a rather insecure way of doing things ...
     
  13. Unread #7 - Oct 28, 2008 at 9:20 AM
  14. -------owned-------
    Joined:
    Jan 27, 2007
    Posts:
    1,225
    Referrals:
    0
    Sythe Gold:
    0

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

    My cryptography function.

    Indeed it is, I'm just trying out some new functions etc.
    I'm new to C.
     
  15. Unread #8 - Dec 15, 2008 at 9:09 PM
  16. DreaDz
    Joined:
    Dec 13, 2008
    Posts:
    62
    Referrals:
    0
    Sythe Gold:
    0

    DreaDz Member

    My cryptography function.

    Use keys, not just a random number gen.
     
  17. Unread #9 - Feb 18, 2009 at 5:24 PM
  18. TheAlchemist
    Joined:
    Feb 18, 2009
    Posts:
    8
    Referrals:
    0
    Sythe Gold:
    0

    TheAlchemist Newcomer

    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! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site