Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Commonmark migration
Source Link

I am using base64 for encryption and decryption.

But for some values, encrypted data is not decrypting properly and add special characters. Using current key, word 'skype' is not encrypting and decrypting correctly instead special characters appear on decrypting.

Can anyone please tell me, what the problem is? (code is simple available on Google but I have checked blogs and forum, can't find any such thing related to this issue, which means problem is in my code) ##encrypt.php##

encrypt.php

<?php
$id= $_GET['id'];
$encrypted = encrypt($id, "check");
echo $encrypted ;
function encrypt($string, $key) 
{
 $result = '';
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)+ord($keychar));
 $result.=$char;
 }
 return base64_encode($result);
}
?>

##decrypt.php##

decrypt.php

<?php
$id= $_GET['id'];
$decrypted = decrypt($id, "check");
echo $decrypted ;
function decrypt($string, $key) 
{
 $result = '';
 $string = base64_decode($string);
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)-ord($keychar));
 $result.=$char;
 }
 return $result;
}
?>

I am using base64 for encryption and decryption.

But for some values, encrypted data is not decrypting properly and add special characters. Using current key, word 'skype' is not encrypting and decrypting correctly instead special characters appear on decrypting.

Can anyone please tell me, what the problem is? (code is simple available on Google but I have checked blogs and forum, can't find any such thing related to this issue, which means problem is in my code) ##encrypt.php##

<?php
$id= $_GET['id'];
$encrypted = encrypt($id, "check");
echo $encrypted ;
function encrypt($string, $key) 
{
 $result = '';
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)+ord($keychar));
 $result.=$char;
 }
 return base64_encode($result);
}
?>

##decrypt.php##

<?php
$id= $_GET['id'];
$decrypted = decrypt($id, "check");
echo $decrypted ;
function decrypt($string, $key) 
{
 $result = '';
 $string = base64_decode($string);
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)-ord($keychar));
 $result.=$char;
 }
 return $result;
}
?>

I am using base64 for encryption and decryption.

But for some values, encrypted data is not decrypting properly and add special characters. Using current key, word 'skype' is not encrypting and decrypting correctly instead special characters appear on decrypting.

Can anyone please tell me, what the problem is? (code is simple available on Google but I have checked blogs and forum, can't find any such thing related to this issue, which means problem is in my code)

encrypt.php

<?php
$id= $_GET['id'];
$encrypted = encrypt($id, "check");
echo $encrypted ;
function encrypt($string, $key) 
{
 $result = '';
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)+ord($keychar));
 $result.=$char;
 }
 return base64_encode($result);
}
?>

decrypt.php

<?php
$id= $_GET['id'];
$decrypted = decrypt($id, "check");
echo $decrypted ;
function decrypt($string, $key) 
{
 $result = '';
 $string = base64_decode($string);
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)-ord($keychar));
 $result.=$char;
 }
 return $result;
}
?>
edited tags; edited tags
Link
Maarten Bodewes
  • 94.6k
  • 15
  • 169
  • 289
improved formatting
Source Link
John Kiernander
  • 4.9k
  • 1
  • 17
  • 29

I am using base64base64 for encryption and decryptionencryption and decryption.

But for some values, encrypted data is not decrypting properly and add special characters. Using current key, word 'skype' is not encrypting and decrypting correctly instead special characters appear on decrypting.

canCan anyone please tell me, what isthe problem. is? (code is simple available on googleGoogle but I have checked blogs and forum, can't find any such thing related to this issue, which means problem is in my code) ##encrypt.php##

<?php
$id= $_GET['id'];
$encrypted = encrypt($id, "check");
echo $encrypted ;
function encrypt($string, $key) 
{
 $result = '';
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)+ord($keychar));
 $result.=$char;
 }
 return base64_encode($result);
}
?>

##decrypt.php##

<?php
$id= $_GET['id'];
$decrypted = decrypt($id, "check");
echo $decrypted ;
function decrypt($string, $key) 
{
 $result = '';
 $string = base64_decode($string);
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)-ord($keychar));
 $result.=$char;
 }
 return $result;
}
?>

I am using base64 for encryption and decryption.

But for some values, encrypted data is not decrypting properly and add special characters. Using current key, word 'skype' is not encrypting and decrypting correctly instead special characters appear on decrypting.

can anyone please tell me, what is problem. (code is simple available on google but I have checked blogs and forum, can't find any such thing related to this issue, which means problem is in my code) ##encrypt.php##

<?php
$id= $_GET['id'];
$encrypted = encrypt($id, "check");
echo $encrypted ;
function encrypt($string, $key) 
{
 $result = '';
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)+ord($keychar));
 $result.=$char;
 }
 return base64_encode($result);
}
?>

##decrypt.php##

<?php
$id= $_GET['id'];
$decrypted = decrypt($id, "check");
echo $decrypted ;
function decrypt($string, $key) 
{
 $result = '';
 $string = base64_decode($string);
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)-ord($keychar));
 $result.=$char;
 }
 return $result;
}
?>

I am using base64 for encryption and decryption.

But for some values, encrypted data is not decrypting properly and add special characters. Using current key, word 'skype' is not encrypting and decrypting correctly instead special characters appear on decrypting.

Can anyone please tell me, what the problem is? (code is simple available on Google but I have checked blogs and forum, can't find any such thing related to this issue, which means problem is in my code) ##encrypt.php##

<?php
$id= $_GET['id'];
$encrypted = encrypt($id, "check");
echo $encrypted ;
function encrypt($string, $key) 
{
 $result = '';
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)+ord($keychar));
 $result.=$char;
 }
 return base64_encode($result);
}
?>

##decrypt.php##

<?php
$id= $_GET['id'];
$decrypted = decrypt($id, "check");
echo $decrypted ;
function decrypt($string, $key) 
{
 $result = '';
 $string = base64_decode($string);
 for($i=0; $i<strlen($string); $i++) {
 $char = substr($string, $i, 1);
 $keychar = substr($key, ($i % strlen($key))-1, 1);
 $char = chr(ord($char)-ord($keychar));
 $result.=$char;
 }
 return $result;
}
?>
Loading
Loading
Source Link
K.Liaqat
  • 143
  • 1
  • 3
  • 15
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /