473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Base64 Decoding

I'm having a problem decoding an encrypted Base64 string (with a key).
I am trying to encode and decode with a url friendly version. It works
if I use them seperate but when I try to put them both in the same
function it doesn't decrypt it right.

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;
}
$base64 = base64_encode($result);
$base64url = strtr($base64, '+/=', '-_,');
return $base64url;
}

function decrypt($string,$key) {
$result = ”;
$string = strtr($string, '-_,', '+/=');
$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;
}

Thanks,
Bryan
Nov 8 '08 #1
1 5148
On Nov 8, 3:38*pm, Bryan A <Bryan.Andr...@gmail.comwrote:
I'm having a problem decoding an encrypted Base64 string (with a key).
I am trying to encode and decode with a url friendly version. It works
if I use them seperate but when I try to put them both in the same
function it doesn't decrypt it right.

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;
* }
* * $base64 = base64_encode($result);
* * $base64url = strtr($base64, '+/=', '-_,');
* * return $base64url;

}

function decrypt($string,$key) {
* $result = ”;
* $string = strtr($string, '-_,', '+/=');
* $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;

}

Thanks,
Bryan
Nevermind. I figured out that I can call another function from inside
another
Nov 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ramy076 | last post by:
I have a C App which uses openssl for Encoding and decoding which needs to be ported to java. The decoded text does not match between the C App and the java App. The size of the output itself is...
1
by: Oliver Kurz | last post by:
Hello, I have a problem by converting a string to base64 and back again. I have a string with german special chars like äöüß. This string i convert with base64str=base64.encode('äöüß') into...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
7
by: Julia | last post by:
Hi I am trying to pass an encoded string to a JavaScript the following is the C# code which convert the string STRING_TO_ENCODE to base64 byte bytIn =...
14
by: BB | last post by:
Hello. i am trying to decode a block of (what i think is) base64 into text, and i have NO idea how to begin. I'm going to paste the whole string here, but i want to know the steps necessary to...
8
by: Jeremy Kitchen | last post by:
I have encoded a string into Base64 for the purpose of encryption. I then later decrypted it and converted it back from Base64 the final string returns with four nothing characters. "pass" what...
10
by: pycraze | last post by:
Hi , I am currently trying to implement base64 encoding and decoding scheme in C . Python has a module , base64 , that will do the encoding and decoding with ease . I am aware of OpenSSL having...
3
by: d-fan | last post by:
void decodebio( unsigned char *encbuf, unsigned char * decbuf, int destbuf ) { /* Read Base64 encoded data from standard input and write the decoded data to standard output: */ BIO...
3
by: ashu | last post by:
I am searching for Win32 (or WinMobile) API for converting ASCII string to Base64 and vice-versa can anyone help me out.... Thanks in advance...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.