How to base64 encode php in this format

0 votes

Can someone please guide me on how to  base64 encode PHP by base64 decode below? 

function fn_one($a){$c='';for ($i=0;$i < strlen($a);$i++) {$b=ord($a[$i]);$c.=chr(--$b);}return $c;}$decode=call_user_func("base64_decode",call_user_func("fn_one","cnGu[R>>"));echo $decode; // Deconde "cnGu[R>>" to "name"

In PHP, the content is encoded as "cnGu[R>>" with the decoding code as below, the output after base64 decoding is "name". 

$encode=call_user_func("base64_encode",call_user_func("fn_one",$decode));echo $encode;// Encode "name" to "cnGu[R>>"

How do I base64 encode "name" in reverse in the format below which results in "name" as "cnGu[R>>"?

Jun 10, 2022 in PHP by narikkadan
• 86,360 points
• 2,944 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Just reverse it, that is, change chr(--$b) to chr(++$b):

<?php
function fn_two($a){$c='';for ($i=0;$i < strlen($a);$i++) {$b=ord($a[$i]);$c.=chr(++$b);}return $c;}

echo fn_two(base64_encode('name'));

Result

cnGu[R>>

I hope this helps you.

answered Jun 12, 2022 by Kithuzzz
• 38,000 points

edited Mar 5, 2025

Related Questions In PHP

0 votes
1 answer

How to properly URL encode a string in PHP?

Hello @kartik, For the URI query use urlencode/urldecode; for ...READ MORE

answered Oct 19, 2020 in PHP by Niroj
• 82,800 points
• 5,004 views
0 votes
1 answer

How to merge two arrays while keeping keys instead of reindexing in php?

Hello, Considering that you have $replaced = array('1' => ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,800 points
• 5,415 views