|
-
Aug 19th, 2009, 09:34 PM
#1
Thread Starter
Junior Member
Total PHP Script
So I found this Visual Basic Program source code. I then converted it to PHP as you can see below. Somewhere along the way I messed up. If you find out where I messed up (I think it may be multiple places) I'll pay you $5. PM! me the new source do NOT post it here.
PHP Code
Code:
<?
function Mid($str,$start,$length)
{
$array = explode('',$str);
$number = $start;
while($length > $number)
{
$return .= $array[$number];
$number++;
}
return $return;
}
function Asc($str)
{
ord($str);
}
function Left($str, $length)
{
return substr($str, 0, $length);
}
function Right($str, $length)
{
$array = explode('',$str);
while($length > -1)
{
$return .= $array[$length];
$length = $length - 1;
}
}
function CLng($str)
{
$array = explode('.',$str);
return $array[0];
}
function Len($str)
{
strlen($str);
}
function Decompress($DecompData)
{
if (Len($DecompData) > 4)
{
$ControlCount = Asc(Left($DecompData, 1)) *16777216 + Asc(Mid($DecompData, 2, 1)) *65536 + Asc(Mid($DecompData, 3, 1)) *256 + Asc(Mid($DecompData, 4, 1));
$DataCount = Asc(Mid($DecompData, 5, 1)) *16777216 + Asc(Mid($DecompData, 6, 1)) *65536 + Asc(Mid($DecompData, 7, 1)) *256 + Asc(Mid($DecompData, 8, 1)) + 9;
$Decompress = Mid($DecompData, $DataCount, 4);
$DataCount = $DataCount + 4;
$ControlBitPos = 0;
$ControlPos = 9;
}
else
{
}
$DataPost = 1;
while($DataPos < $ControlCount)
{
if(pow(2, $ControlBitPos) == (ord(substr($DecompData, $ControlPos, 1))) && pow(2, $ControlBitPos))
{
$DecompStart = Len($Decompress) - (CLng(Asc(Mid($DecompData, $DataCount, 1))) *256 + CLng(Asc(Mid($DecompData, $DataCount + 1, 1)))) + 1;
$DecompLen = Asc(Mid($DecompData, $DataCount + 2, 1));
$Decompress = $Decompress & Mid($Decompress, $DecompStart, $DecompLen);
$DataCount = $DataCount + 3;
}
else
{
$Decompress = $Decompress . Mid($DecompData, $DataCount, 1);
$DataCount++;
}
$ControlBitPos++;
if($ControlBitPos = 8)
{
$ControlBitPos = 0;
$ControlPos++;
}
else
{
$Decompress = $DecompData;
}
$DataPos++;
}
}
$FileName = 'test.bin';
$FName = $FileName;
$string56 = array_merge(range('0', '9') , range('a' , 'z'));
$string56 = array_merge($string56 , range('A' , 'Z'));
$zero = '0';
while($zero < 6) { $full .= $string56[rand('0' , count($string56))]; $zero++; }
$data = file_get_contents($FileName);
$return = Decompress($FileName);
$file = fopen($full . '.jpg','w');
fwrite($file,$return);
fclose($file);
echo $return . '<br /><br />';
echo $full . '.jpg';
?>
Visual Basic Code
Code:
Public Function sDecompress(sDecompData As String) As String
Dim lControlCount As Long
Dim lControlPos As Long
Dim bControlBitPos As Byte
Dim lDataCount As Long
Dim lDataPos As Long
Dim lDecompStart As Long
Dim lDecompLen As Long
If Len(sDecompData) > 4 Then
lControlCount = Asc(Left(sDecompData, 1)) * &H1000000 + Asc(Mid(sDecompData, 2, 1)) * &H10000 + Asc(Mid(sDecompData, 3, 1)) * &H100 + Asc(Mid(sDecompData, 4, 1))
lDataCount = Asc(Mid(sDecompData, 5, 1)) * &H1000000 + Asc(Mid(sDecompData, 6, 1)) * &H10000 + Asc(Mid(sDecompData, 7, 1)) * &H100 + Asc(Mid(sDecompData, 8, 1)) + 9
sDecompress = Mid(sDecompData, lDataCount, 4)
lDataCount = lDataCount + 4
bControlBitPos = 0
lControlPos = 9
For lDataPos = 1 To lControlCount
If 2 ^ bControlBitPos = (Asc(Mid(sDecompData, lControlPos, 1)) And 2 ^ bControlBitPos) Then
lDecompStart = Len(sDecompress) - (CLng(Asc(Mid(sDecompData, lDataCount, 1))) * &H100 + CLng(Asc(Mid(sDecompData, lDataCount + 1, 1)))) + 1
lDecompLen = Asc(Mid(sDecompData, lDataCount + 2, 1))
sDecompress = sDecompress & Mid(sDecompress, lDecompStart, lDecompLen)
lDataCount = lDataCount + 3
Else
sDecompress = sDecompress & Mid(sDecompData, lDataCount, 1)
lDataCount = lDataCount + 1
End If
bControlBitPos = bControlBitPos + 1
If bControlBitPos = 8 Then
bControlBitPos = 0
lControlPos = lControlPos + 1
End If
Next
Else
sDecompress = sDecompData
End If
End Function
'Put a two command buttons (Command1 and
' Command2) on to a form and paste the fol
' lowing on to it as well:
Option Explicit
Private Const sFileName = "c:\compressthis.exe" ' the file To be compressed
Private Sub Command1_Click() 'Compress the file
Dim sReturn As String
Dim sFileData As String
Open sFileName For Binary As #1
sFileData = Input(LOF(1), #1)
Close #1
sReturn = sCompress(sFileData)
Debug.Print Len(sReturn), Len(sFileData)
Open Left(sFileName, Len(sFileName) - 3) & "wnc" For Output As #1
Print #1, sReturn;
Close #1
End Sub
Private Sub Command2_Click() 'Decompress the file
Dim sReturn As String
Dim sFileData As String
Open Left(sFileName, Len(sFileName) - 4) & ".wnc" For Binary As #1
sFileData = Input(LOF(1), #1)
sReturn = sDecompress(sFileData)
Close #1
Debug.Print Len(sReturn), Len(sFileData)
Open Left(sFileName, Len(sFileName) - 4) & "2" & Right(sFileName, 4) For Output As #1
Print #1, sReturn;
Close #1
End Sub
Last edited by pudge1; Aug 19th, 2009 at 09:38 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|