Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This code by it's self doesn't compress..

But when used in conjunction with Zlib it compresses..

See compress_loop()

it starts a the end of the hex input stream and squares each digit.
if puts the last hex digit into the output, and carry's the remainder to the next input digit.

I'm looking for someone who can decompress it's output...

[edit]
From OP, posted as a solution:
Quote:
The source is written in FreeBasic
[/edit]

What I have tried:

Declare Function      compress_loop( chrs as string ) as string
Declare Function decompress_loop( chrs as string ) as string

screen 19
'=====================================================================
'=====================================================================
'start program
'=====================================================================
'=====================================================================
dim as double time1 , time2 , time3 , time4
do
   
    randomize
   
    dim as string s = ""
    For n As Long = 1 To 8
        s+=chr(Int(Rnd*256))
    Next
   
    time1=timer
    'begin compress
        dim as string comp = s
            'do
            '    dim as longint chk = len(comp) - 1
            '    comp = compress_loop(comp)
            '    if len(comp) >= chk then exit do
            'loop
            for a as longint = 1 to 1 step 1
                comp = compress_loop(comp)
            next
    'end compress
    time2 = timer
   
    time3=timer
    'begin decompress
        dim as string final_out = comp
        for a as longint = 1 to 1 step 1
            final_out = decompress_loop(final_out)
        next
    'end decompress
    time4 = timer
   
   'sleep
   
    'cls
    'draw string( 0,10) , left(s,100)
    'draw string( 0,30) , left(final_out,100)
    print string(99,"=")
    print "inp = " ; (s)
    print string(99,"=")
    print "out = " ; (final_out)
    print
    print "compress time   = "; time2-time1
    print "decompress time = "; time4-time3
    print
   
    if s = final_out then print "Decompressed OK" else print "Decompression failed."
    print string(99,"=")
   
    sleep
   
loop until inkey = chr(27)

sleep
end
'===============================================================================
'===============================================================================
'compress
'===============================================================================
'===============================================================================
Function compress_loop( chrs as string ) as string
   
    print "c inp = " ; len(chrs)
   
    dim as string bits = ""
    dim as string zeros = string( 2 , "0" )
    dim as string n1
    dim as ubyte ptr usp = cptr( ubyte ptr , strptr( chrs ) )
    for a as longint = 1 to len( chrs ) step 1
        n1 = zeros + hex( *usp ) : usp+= 1
        n1 = right( n1 , 2 )
        bits+= n1
    next
   
    print "c bin = " ; len(bits) , bits
    
    dim as string outs1 = string( len( bits ) , "0" )
    dim as string s1 , s2 , s3
    dim as longint v1 , v2 , carry
    zeros = "000"
    for a as longint = len( bits ) to 1 step - 1
            
            's1 = str( ( val( "&H" + mid( bits , a , 1 ) ) ^ 2 ) + carry ) : carry = 0
            's2 = right( "000" + hex( val( s1 ) ) , 3 )
            
            v1 = bits[ a - 1 ]
            
            if v1 = 48 then v2 = 000 + carry : goto done
            if v1 = 49 then v2 = 001 + carry : goto done
            if v1 = 50 then v2 = 004 + carry : goto done
            if v1 = 51 then v2 = 009 + carry : goto done
            if v1 = 52 then v2 = 016 + carry : goto done
            if v1 = 53 then v2 = 025 + carry : goto done
            if v1 = 54 then v2 = 036 + carry : goto done
            if v1 = 55 then v2 = 049 + carry : goto done
            if v1 = 56 then v2 = 064 + carry : goto done
            if v1 = 57 then v2 = 081 + carry : goto done
            if v1 = 65 then v2 = 100 + carry : goto done
            if v1 = 66 then v2 = 121 + carry : goto done
            if v1 = 67 then v2 = 144 + carry : goto done
            if v1 = 68 then v2 = 169 + carry : goto done
            if v1 = 69 then v2 = 196 + carry : goto done
            if v1 = 70 then v2 = 225 + carry : goto done
            
            done:
            
            carry = 0
            
            s2 = zeros + hex( v2 )
            s2 = right( s2 , 3 )
            
            carry = val( "&H" + left( s2 , 2 ) ) 
            s3 = right( s2 , 1 )

            outs1[ a - 1 ] = s3[ 0 ]
            
            'print v1 ,  s2 , s3 ', outs1
            'sleep
            'if inkey = " " then end
            
    next
    
    if carry > 0 then outs1 = hex( carry ) + outs1
    
    print "c out = " ; len( outs1 ) , outs1
    
    dim as ubyte count = 0
    if len( outs1 ) mod 2 = 1 then outs1+= "0" : count = 1
        
    dim as string final = ""
    for a as longint = 1 to len( outs1 ) step 2
        final+= chr( val( "&H" + mid( outs1 , a , 2 ) ) )
    next
    
    final = chr( count ) + final
    
    print "c fin = " ; len(final)
   
    return final
   
end function
'===============================================================================
'============================================================================
Function decompress_loop( chrs as string ) as string
   
    print "dc inp = " ; len(chrs)
    
    dim as ubyte count = asc( left( chrs , 1 ) )
    chrs = mid( chrs , 2 )
    
    dim as string bits = ""
    dim as string zeros = string( 2 , "0" )
    dim as string n1
    dim as ubyte ptr usp = cptr( ubyte ptr , strptr( chrs ) )
    for a as longint = 1 to len( chrs ) step 1
        n1 = zeros + hex( *usp ) : usp+= 1
        n1 = right( n1 , 2 )
        bits+= n1
    next
    
    bits = left( bits , len( bits ) - count )
    
    print "d bin = " ; len(bits) , bits
   
    return chrs 
   
end function
Posted
Updated 23-Nov-19 7:26am
v2

Having sorted your "additional info solution", I looked at the question, and ...

No. It doesn't quite work like that. We're not going to reverse engineer a large chunk of code for you - that's either your work and you are getting paid for it, or it's part of your homework and it wouldn't be fair on you, your classmates, or your future employer.

We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.
 
Share this answer
 
Maybe you can try the Zlib example here: fbc/zlib.bas at master · freebasic/fbc · GitHub[^]
 
Share this answer
 
Quote:
How do I decompress this code?

Difficult to guess what you want because the code provided is not compressed and is not about compression.
We have to guess what the word 'compression' means in your head.
There is nothing we can do for you until you explain clearly what you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900