Squares

General FreeBASIC programming questions.
Locked
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Richard

I found a formula to reverse an XOR

Code: Select all


screen 19

for a as longint = 0 to 255
    
    print a , a xor 2 , 0 eqv ((a xor 2) eqv 2)
    
    
    if a mod 16 = 0 then sleep
    
next

sleep
end

badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Post by badidea »

Xor can reverse itself:

Code: Select all

print a , a xor 2 , (a xor 2) xor 2
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@badidea

Problem is:
Xor's don't compress ; they are 1:1 compression...

If you can find a formula to reverse an OR , then it would compress like 60% to 90+% each run.

The problem with OR' is ; they run in 2's , 0101 3434 5656 , 10 11 10 11 , so theres two of each number you have to figure out..
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Dodicat

How do you compress a folder with your ZIP code??

I need to compress strings , so i can recurse each file to optimize it's compression..

But then i need to be able to compress a folder and all it's files. Each file needs to run through the compressor 10+ times.

Then we need to figure out how to get a computers "host-name" through the internet.
So we can stick the name into the program and zip it , before it's downloaded.

I'll split the income 4 ways , Dodicat , Albert , Richard , Zlib people.
Richard has been a downer on the compression idea , but I've used so much of his code in my programs, i thought I'd include him anyways.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Post by badidea »

albert wrote: If you can find a formula to reverse an OR
Impossible, information is lost with the OR operation.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@badidea

I found a way to reverse an OR .. Only thing is i don't know what "a" is supposed to =

"a" is what our trying to figure out , and it uses "a" to solve for "a"

Code: Select all


screen 19

dim as single v1 , v2 , v3 , v4
for a as longint = 0 to 255
    
    v1 = a or 2
    
    'don't know what a = for (a or 1) 
    v2 = (a or 1) - ((a or 2) or -2)
    if v2 mod 2 = 0 then v2-=1 else v2-=3
    
    print "a = " ; a , "a or 2 = " ; v1 ,, "undo = " ; v2
    
    if a mod 16 = 0 then sleep
    
next

sleep
end

Last edited by albert on Apr 01, 2019 18:46, edited 1 time in total.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Squares

Post by fxm »

;-(
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Post by badidea »

Really?

v1 = a or 2 means that that you set bit 2 of a number v1 to 1. So you erase that bit of information.

Then you use a to determine the value of v2, which is 'not allowed'.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Post by Richard »

Albert wrote:Richard has been a downer on the compression idea , but I've used so much of his code in my programs, i thought I'd include him anyways.
@Albert. Please don't include or associate me with your data compression ideas. I would really like to maintain some distance between myself and the liability. I am sorry but you are so dazzled by the dream of dollars that you cannot hear or understand the voices of reason to see the fundamental impossibility of your beliefs.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Post by dodicat »

Hi Albert.
I have been messing around with Python coding.

Regarding injecting a string into a .exe file, freebasic has loads of repititions of stuff like
"GCC: (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project)" in 64 bit .exe files.
You can use this section of the exe to write your own strings.
Example, 64 bit (don't know about wine .exe files though, they could be different!)

Code: Select all

 
Function tally (somestring As String,partstring As String,arr() As Integer) As Integer
    Dim As Integer i,j,ln,lnp,count,num
    Dim As boolean filler=false
    ln=Len(somestring)
    lnp=Len(partstring)
    start:
    count=0
    i=-1
    Do
        i+=1
        If somestring[i] <> partstring[0] Then Goto skip 
        If somestring[i] = partstring[0] Then
            For j=0 To lnp-1 
                If somestring[j+i]<>partstring[j] Then Goto skip
            Next j
        End If
        count+=1
        If filler = true Then arr(count)=i+1 
        i=i+lnp-1
        skip:
    Loop Until i>=ln-1 
    If filler = false Then Redim arr(count) 'size is now known, repeat the operation to fill arr()
    arr(0)=count                            '  save tally in (0)
    num=count
    If filler=true Then Goto _return
    filler=true
    Goto start
    _return:
    Return num
End Function


 #Include "file.bi"

Function loadfile(file as string) as String
	If FileExists(file)=0 Then Print file;" not found":Sleep:end
   var  f=freefile
    Open file For Binary Access Read As #f
    Dim As String text
    If Lof(f) > 0 Then
      text = String(Lof(f), 0)
      Get #f, , text
    End If
    Close #f
    return text
end Function

Sub savefile(filename As String,p As String)
    Dim As Integer n
    n=Freefile
    If Open (filename For Binary Access Write As #n)=0 Then
        Put #n,,p
        Close
    Else
        Print "Unable to save " + filename
    End If
End Sub


Sub replace(s As String,position As Integer,chars As String)
    var L=len(chars)
    mid(s,position,L)=chars
End Sub

redim as integer s()

var L=loadfile("C:\Users\User\Desktop\shell64.exe") '<----------- your file in here

dim as string find="GCC: (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project)"

print "File length ";len(L)
print "Repititions ";tally(L,find,s());"  of:"
print find


dim as string g=string(len(find),"Z")
print
print "position to insert this:"
print g;"  =  ";s(1)

replace(L,s(1),g)

savefile("_shell64.exe",L)
print "done"

sleep
 
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Dodicat

I found a way to compress "random data" , str+= chr( int( rnd*256 ) )

After 40 loops it compresses down to 54%

I still need to write a de-compressor for it.

If the string has fewer than a certain number of repeats , it just leaves it alone and doesn't try to alter it.
So the dictionary stays small..
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Dodicat

I found an error in my compression attempt.
Last edited by albert on Apr 04, 2019 1:03, edited 1 time in total.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Dodicat

Figured the dilema out...Now to work on a de-compressor....

Get ready to be a billionaire.....
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Dodicat

Found a problem with my compressing...

If you build a dictionary of bytes in the file..
And bubble sort the dictionary, so the most prolific bytes are first.

If you then redim preserve , the dictionary to 127 chars. And then search the file for those 127 bytes and replace them with a 0 to 127 pointer.
And leave all the bytes that aren't in the dictionary alone.

Some of the bytes in the file that aren't in the dictionary , might equal a 0 to 127 dictionary pointer.
If you add 128 to the dictionary pointer , then some of the bytes in the file might equal the ( 0+128 ) dictionary pointer..

If you leave the dictionary at 255 chars, then it doesn't compress..

Maybe i need to try a binary dictionary?
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Post by albert »

@Dodicat

I tried a binary dictionary and it worked...

How do you compress a folder with your Zip code??
Locked