brooksh Posted January 11, 2008 Share Posted January 11, 2008 I want to encrypt the ID number into another number. But then I want to be able to decrypt the encrypted number so that I can see the original number. Any simple ideas would be appreciated. $original_num = "123-45"; $encrypted_num = encrypt($original_num); echo $encrypted_num; //$encrypted_num = somthing like 73632 $decrypted_num = decrypt($encrypted_num); echo $decrypted_num; Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/ Share on other sites More sharing options...
drummer101 Posted January 11, 2008 Share Posted January 11, 2008 Give http://www.tonymarston.co.uk/php-mysql/encryption.htm a look. It describes a reversible encryption routine for PHP. There is an online test harness so you can see it working, and you have access to the code as well. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436821 Share on other sites More sharing options...
p2grace Posted January 11, 2008 Share Posted January 11, 2008 Here's a simple method: $original = 123; $secure = rand(100,999).base64_encode($original); $unsecure = substr($secure,3); $unsecure = base_64_decode($unsecure); echo $unsecure; // will display 123 Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436824 Share on other sites More sharing options...
drummer101 Posted January 11, 2008 Share Posted January 11, 2008 wouldn't it just be: echo $unsecure; Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436827 Share on other sites More sharing options...
brooksh Posted January 11, 2008 Author Share Posted January 11, 2008 Thanks, but is it possible to make $secure display only as a number? Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436832 Share on other sites More sharing options...
p2grace Posted January 11, 2008 Share Posted January 11, 2008 How secure do you need it to be? You could create a simple algorithm to encrypt and decrypt it with. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436836 Share on other sites More sharing options...
brooksh Posted January 11, 2008 Author Share Posted January 11, 2008 It doesn't need to be secure at all. I just don't want a basic user to figure out the real number. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436838 Share on other sites More sharing options...
nikefido Posted January 11, 2008 Share Posted January 11, 2008 I'm not an encryption expert by any means but many encryptions are designed so you can't decrypt back to the original (which is why you see the encrypted passwords in databases) example = "md5" or "sha" I assume base_64 doesn't work this way, however, right? Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436840 Share on other sites More sharing options...
brooksh Posted January 11, 2008 Author Share Posted January 11, 2008 There are many encrypt and decrypt scripts out there. Some of them include a password so it is harder to decrypt. But I'm still looking for a script that will convert everything into a number. And yes base64 can be decrypted. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436843 Share on other sites More sharing options...
p2grace Posted January 11, 2008 Share Posted January 11, 2008 base_64 can be decrypted. If all you're looking for is a simple method of encrypting and it doesn't need to be secure you do something as simple as multiplying it by 17 and adding "32" to it. then to decrypt subtract "32" and divide by 17. (Or whatever numbers you'd want to use) Easy enough, but again not secure. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436845 Share on other sites More sharing options...
brooksh Posted January 11, 2008 Author Share Posted January 11, 2008 This was my first thought, but each number has a "-" in it. I am just looking for some script out there that jumbles up the number. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436847 Share on other sites More sharing options...
DyslexicDog Posted January 11, 2008 Share Posted January 11, 2008 So it's not a number then, it is a string. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436853 Share on other sites More sharing options...
roopurt18 Posted January 11, 2008 Share Posted January 11, 2008 <?php // encrypt $num = "123-45"; // starting number $hyphen = !($tmp = strpos($num, '-')) ? 0 : $tmp; // locate the hyphen position $num = str_replace('-', '', $num); // remove the hyphen $num = $num * 4; // alter the number however you like $num = (int)($hyphen . $num); // prefix the hyphen position to altered number and convert back to int echo $num; // decrypt $hyphen = substr($num, 0, 1); // get hyphen position $num = substr($num, 1); // trim hyphen position off the string $num = $num / 4; // undo the number alteration // put the hyphen back in the number $num = substr($num, 0, $hyphen) . '-' . substr($num, $hyphen + 1); echo $num; ?> I might be off on the indexes in that second to last line, but that should give you an idea of a simple alteration you can make. Feel fee to make it as complicated as you want. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436856 Share on other sites More sharing options...
p2grace Posted January 11, 2008 Share Posted January 11, 2008 Give http://www.tonymarston.co.uk/php-mysql/encryption.htm a look. It describes a reversible encryption routine for PHP. There is an online test harness so you can see it working, and you have access to the code as well. This website appears to be down Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436858 Share on other sites More sharing options...
p2grace Posted January 11, 2008 Share Posted January 11, 2008 wouldn't it just be: echo $unsecure; yeah I was trying to show it would equal 123. I edited it to show it in comments. Quote Link to comment https://forums.phpfreaks.com/topic/85597-converting-a-number-to-another-number-encrypt-decrypt/#findComment-436860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.