Jump to content

Base 64 to Binary then flip parts of the Binary to real numbers


Headchopperz

Recommended Posts

hey

im working on a problem and i cant fix it

http://forum.thegamecreators.com/?m=forum_view&t=143736&b=20

 

that is a lnk where i piuut a very detailed review on what i am stuck on

 

ill go over it quickly

in guild wars you get a code in BASE 64 and i need to convert it into Binary

i explain on the other forums that every certain amount of number of digits i need together

then i flip them

eg 0110 1101 becomes 0110 1011

then i do more flipping etc and at the end i convert the binary to real numbers

like 0011 is 3 and then using the numbers i find out the spell etc

 

ive already done this by hand as shown on that link i just dont know how to get it working with PHP

if java works with PHP which im sure it does than i dont mind it being in JAVA if its easier

 

ty for your time

 

Link to comment
Share on other sites

base_convert

 

and to "flip" the numbers you could simply use array_walk on your exploded string

 

for example

<?php
function flipele(&$ele) {
$z = '';
for ($i = 0; ($a = $ele{$}) !== false; $i++) {
	$z = $a.$z;
}
$ele = $z;
}
$string = "0110 1011";
$arr = explode(" ",$string);
array_walk($arr,"flipele");
print_r($arr);
?>

Link to comment
Share on other sites

oooh I'm sorry!!! lol

 

I tested it then edited it and I messed it up :)

 

<?php
function flipele(&$ele) {
$z = '';
for ($i = 0; ($a = $ele{$i}) !== false; $i++) {
	$z = $a.$z;
}
$ele = $z;
}
$string = "0110 1011";
$arr = explode(" ",$string);
array_walk($arr,"flipele");
print_r($arr);
?>

 

there use that bro I'm sorry

Link to comment
Share on other sites

<?php

$original = '00111010000001000100010101110000101101001001100110100000

10100110110001000011100110000110010001010110111100001011

10100000110100010111010001000100101001110000011010001001';

$neworiginal = substr($original,0,4)

$neworiginal = strrev($neworiginal)

$neworiginal = trim ( $neworiginal)

echo $original

echo $neworiginal

?>

 

code ive been trying

Link to comment
Share on other sites

after its fliped i need all the bits back together

like 11001011

fliped = 0011 1101

then i need it to be = 00111101

 

<?php

function zwalk(&$element) {

$element = strrev($element);

}

$original = '00111010000001000100010101110000101101001001100110100000

10100110110001000011100110000110010001010110111100001011

10100000110100010111010001000100101001110000011010001001';

$oldarray = $originalArray;

$originalArray = explode(' ',trim(chunk_split($original,6,' ')));

$originalArray = $originalArray.$oldarray;

array_walk($originalArray,'zwalk');

print_r($originalArray);

print_r($oldarray);

?>

 

that doesnt work ><

Link to comment
Share on other sites

i made a working code but it needs arrays implemented  cos its like loads of code xD

 

<?php
$original = '001110100000010001000101011100001011010010011001101000001010011011000100001110011000011001000101011011110000101110100000110100010111010001000100101001110000011010001001';

$neworiginal1 = substr($original,0,6);
$neworiginal1 = strrev($neworiginal1);
$neworiginal1 = trim($neworiginal1);
echo $original;
echo "\n stuff: ";
echo $neworiginal1;
echo " ";


$neworiginal2 = substr($original,6,6);
$neworiginal2 = strrev($neworiginal2);
$neworiginal2 = trim($neworiginal2);
echo $neworiginal2;
echo " ";

$neworiginal2 = substr($original,12,6);
$neworiginal2 = strrev($neworiginal2);
$neworiginal2 = trim($neworiginal2);
echo $neworiginal2;
echo " ";

$neworiginal3 = substr($original,18,6);
$neworiginal3 = strrev($neworiginal3);
$neworiginal3 = trim($neworiginal3);
echo $neworiginal3;
echo " ";

$neworiginal4 = substr($original,24,6);
$neworiginal4 = strrev($neworiginal4);
$neworiginal4 = trim($neworiginal4);
echo $neworiginal4;
echo " ";

$neworiginal5 = substr($original,30,6);
$neworiginal5 = strrev($neworiginal5);
$neworiginal5 = trim($neworiginal5);
echo $neworiginal5;
echo " ";

$neworiginal6 = substr($original,36,6);
$neworiginal6 = strrev($neworiginal6);
$neworiginal6 = trim($neworiginal6);
echo $neworiginal6;
echo " ";

$neworiginal7 = substr($original,42,6);
$neworiginal7 = strrev($neworiginal7);
$neworiginal7 = trim($neworiginal7);
echo $neworiginal7;
echo " ";

$neworiginal8 = substr($original,48,6);
$neworiginal8 = strrev($neworiginal8);
$neworiginal8 = trim($neworiginal8);
echo $neworiginal8;
echo " ";

$neworiginal9 = substr($original,54,6);
$neworiginal9 = strrev($neworiginal9);
$neworiginal9 = trim($neworiginal9);
echo $neworiginal9;
echo " ";

$neworiginal10 = substr($original,60,6);
$neworiginal10 = strrev($neworiginal10);
$neworiginal10 = trim($neworiginal10);
echo $neworiginal10;
echo "\n ";


$newamount=$neworiginal1.$neworiginal2.$neworiginal3.$neworiginal4.$neworiginal5.$neworiginal6.$neworiginal7.$neworiginal8.$neworiginal9.$neworiginal10;
echo $newamount;
echo " ";

$newamount1 = substr($newamount,0,4);
$newamount1 = strrev($newamount1);
$newamount1 = trim($newamount1);
echo $newamount1;
echo " ";

$newamount2 = substr($newamount,4,4);
$newamount2 = strrev($newamount2);
$newamount2 = trim($newamount2);
echo $newamount2;
echo " ";

$newamount3 = substr($newamount,8,2);
$newamount3 = strrev($newamount3);
$newamount3 = trim($newamount3);
echo $newamount3;
echo " ";

$newamount4 = substr($newamount,10,4);
$newamount4 = strrev($newamount4);
$newamount4 = trim($newamount4);
echo $newamount4;
echo " ";

$newamount5 = substr($newamount,14,4);
$newamount5 = strrev($newamount5);
$newamount5 = trim($newamount5);
echo $newamount5;
echo " ";


$newamount6 = substr($newamount,18,4);
$newamount6 = strrev($newamount6);
$newamount6 = trim($newamount6);
echo $newamount6;
echo " ";





?>

Link to comment
Share on other sites

the problem is urs only does the firt but

and theres like 4 bits

 

 

i tried doing all 4 bits but it fails

<?php

function convert(&$binary) {
$conbinary = substr($binary,$farin,-1);


if $conbinary = 1;
	if $farin = 4 then $conbinary2=1
	if $farin = 3 then $conbinary2=2
	if $farin = 2 then $conbinary2=4
	if $farin = 1 then $conbinary2=8
endif

if $farin=1
$convertedbinary = $conbinary+$conbinary+$conbinary+$conbinary
$farin=5
endif

$farin = $farin-1;

}

function zwalk(&$element) {

	$element = strrev($element);

}

function cutitup(&$cutup) {
	if $binaryno=3
	$cutup = 2
	endif

	if $binaryno=1
	$cutup = 6
	endif

	if $binaryno=2
	$cutup = 4
	endif

	if $binaryno=4
	$cutup = 8
	endif

	$wayin = $wayin + $cutup

	substr($original,$wayin,$cutup);

}

function trimit(&$trimitup) {
	trim($trimitup);
}

function slapittogether(&$slapit) {
	$newamount = $neworiginal1.$neworiginal2.$neworiginal3.$neworiginal4.$neworiginal5.$neworiginal6.$neworiginal7.$neworiginal8.$neworiginal9.$neworiginal10.$neworiginal11;
}

$original = '00111010000001000100010101110000101101001001100110100000
10100110110001000011100110000110010001010110111100001011
10100000110100010111010001000100101001110000011010001001
';

$binary=1


//repeat untill the end, how do i do?

array_walk($original,'trimit');
array_walk2($original,'cutitup');
array_walk3($original,'zwalk');




$newamount = $neworiginal1.$neworiginal2.$neworiginal3.$neworiginal4.$neworiginal5.$neworiginal6.$neworiginal7.$neworiginal8.$neworiginal9.$neworiginal10.$neworiginal11;

// repeat twice
$binary = 2


array_walk($original,'trimit');
array_walk2($original,'cutitup');
array_walk3($original,'zwalk');

// do once

$binary = 3

array_walk($original,'trimit');
array_walk2($original,'cutitup');
array_walk3($original,'zwalk');

// repeat untill end
$binary = 2

?>

Link to comment
Share on other sites

if u look here

http://www.outscape.org/test/convert.php

it does it all sole the converting well not exactly it all

its too much code and too long winded

 

its just doing part of it like the first half of the binary

 

<?php


$original = '00111010000001000100010101110000101101001001100110100000
10100110110001000011100110000110010001010110111100001011
10100000110100010111010001000100101001110000011010001001
';

$neworiginal1 = substr($original,0,6);
$neworiginal1 = strrev($neworiginal1);
$neworiginal1 = trim($neworiginal1);
echo $original;
echo "\n stuff: ";
echo $neworiginal1;
echo " ";


$neworiginal2 = substr($original,6,6);
$neworiginal2 = strrev($neworiginal2);
$neworiginal2 = trim($neworiginal2);
echo $neworiginal2;
echo " ";

$neworiginal3 = substr($original,12,6);
$neworiginal3 = strrev($neworiginal3);
$neworiginal3 = trim($neworiginal3);
echo $neworiginal3;
echo " ";

$neworiginal4 = substr($original,18,6);
$neworiginal4 = strrev($neworiginal4);
$neworiginal4 = trim($neworiginal4);
echo $neworiginal4;
echo " ";

$neworiginal5 = substr($original,24,6);
$neworiginal5 = strrev($neworiginal5);
$neworiginal5 = trim($neworiginal5);
echo $neworiginal5;
echo " ";

$neworiginal6 = substr($original,30,6);
$neworiginal6 = strrev($neworiginal6);
$neworiginal6 = trim($neworiginal6);
echo $neworiginal6;
echo " ";

$neworiginal7 = substr($original,36,6);
$neworiginal7 = strrev($neworiginal7);
$neworiginal7 = trim($neworiginal7);
echo $neworiginal7;
echo " ";

$neworiginal8 = substr($original,42,6);
$neworiginal8 = strrev($neworiginal8);
$neworiginal8 = trim($neworiginal8);
echo $neworiginal8;
echo " ";

$neworiginal9 = substr($original,48,6);
$neworiginal9 = strrev($neworiginal9);
$neworiginal9 = trim($neworiginal9);
echo $neworiginal9;
echo " ";

$neworiginal10 = substr($original,54,6);
$neworiginal10 = strrev($neworiginal10);
$neworiginal10 = trim($neworiginal10);
echo $neworiginal10;
echo " ";

$neworiginal11 = substr($original,60,6);
$neworiginal11 = strrev($neworiginal11);
$neworiginal11 = trim($neworiginal11);
echo $neworiginal11;
echo "\n ";


$newamount = $neworiginal1.$neworiginal2.$neworiginal3.$neworiginal4.$neworiginal5.$neworiginal6.$neworiginal7.$neworiginal8.$neworiginal9.$neworiginal10.$neworiginal11;
echo $newamount;
echo "\n hi ";

$newamount1 = substr($newamount,0,4);
$newamount1 = strrev($newamount1);
$newamount1 = trim($newamount1);
echo $newamount1;
echo " ";

$newamount2 = substr($newamount,4,4);
$newamount2 = strrev($newamount2);
$newamount2 = trim($newamount2);
echo $newamount2;
echo " ";

$newamount3 = substr($newamount,8,2);
$newamount3 = strrev($newamount3);
$newamount3 = trim($newamount3);
echo $newamount3;
echo " ";

$newamount4 = substr($newamount,10,4);
$newamount4 = strrev($newamount4);
$newamount4 = trim($newamount4);
echo $newamount4;
echo " ";

$newamount5 = substr($newamount,14,4);
$newamount5 = strrev($newamount5);
$newamount5 = trim($newamount5);
echo $newamount5;
echo " ";


$newamount6 = substr($newamount,18,4);
$newamount6 = strrev($newamount6);
$newamount6 = trim($newamount6);
echo $newamount6;
echo " ";



?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.