Squares

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

Re: Squares

Postby albert » Mar 31, 2019 21:40

@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: 1466
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Postby badidea » Mar 31, 2019 22:31

Xor can reverse itself:

Code: Select all

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

Re: Squares

Postby albert » Mar 31, 2019 22:55

@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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Apr 01, 2019 0:37

@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: 1466
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Squares

Postby badidea » Apr 01, 2019 6:43

albert wrote:If you can find a formula to reverse an OR

Impossible, information is lost with the OR operation.
albert
Posts: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Apr 01, 2019 17:29

@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
Posts: 9137
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Squares

Postby fxm » Apr 01, 2019 18:05

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

Re: Squares

Postby badidea » Apr 01, 2019 19:06

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: 2953
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Apr 01, 2019 20:05

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: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Squares

Postby dodicat » Apr 03, 2019 0:27

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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Apr 04, 2019 0:21

@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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Apr 04, 2019 0:40

@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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Apr 04, 2019 1:03

@Dodicat

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

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

Re: Squares

Postby albert » Apr 04, 2019 2:43

@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: 4952
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Apr 04, 2019 19:38

@Dodicat

I tried a binary dictionary and it worked...

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

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests