Menu

#979 Banned From Forum

closed
nobody
None
other
2023-05-11
2023-05-05
No

Hello Guys;

Albert Redditt here..

I was banned from the FB forum for posting compression formulas that didn't work..

I've finally got a working compression formula..

( !!~~YAHOO~~!! ) ( Recursive Lossless Random Data Compression )

Here's the compression loop..

dim as string m1 , m2
dim as ubyte in
for a as longint = 0 to len( chrs ) - 1 step 1

    in = chrs[a]

    if in >= 000 and in <= 031 then m1 = "0"
    if in >= 032 and in <= 063 then m1 = "1"
    if in >= 064 and in <= 095 then m1 = "2"
    if in >= 096 and in <= 127 then m1 = "3"

    if in >= 128 and in <= 159 then m1 = "4"
    if in >= 160 and in <= 191 then m1 = "5"
    if in >= 192 and in <= 239 then m1 = "6"
    if in >= 240 and in <= 255 then m1 = "7"

    m2 = oct( in mod 32 )

    m2+= m1

    chrs[a] = val( "&O" + m2 )

next

Can you un-ban me so i can post of the forum???

Attached Files

1 Attachments

Related

Bugs: #980

Discussion

  • Albert Redditt

    Albert Redditt - 2023-05-05

    You pass the output "chrs" to a zip library and then keep looping until it can't get any smaller..

    Compresses any size file down to 4800 bytes.

     
  • TeeEmCee

    TeeEmCee - 2023-05-06

    Hi Albert.

    Let's keep this off the forum. There's no need to bother anyone else. You're probably going to ignore my message. Please don't be a jerk, actually read it. You're banned from the forum because you ignore EVERYTHING that anyone writes to you. Which makes it pointless for you to be on a forum.

    Your compression loop contains a subtle bug. It looks like it reorders the bits of chrs[a], moving the top 3 bits (value from 0 to 7) to the back. That can be written much more simply, and far, far more efficiently as:

        dim as ubyte top3, bottom5
        dim as ubyte in
        for a as longint = 0 to len( chrs ) - 1  step 1
            in = chrs[a]
            top3 = in shr 5
            bottom5 = in and 31
            chrs[a] = (bottom5 shl 3) or top3
        next
    

    Learn what the bitshift operators shl and shr and bitwise operators and and or do, they are very useful.

    Anyway, your bug is that the lines

            if in >= 192 and in <= 239 then m1 = "6"
            if in >= 240 and in <= 255 then m1 = "7"
    

    should be

            if in >= 192 and in <= 223 then m1 = "6"
            if in >= 224 and in <= 255 then m1 = "7"
    

    This bug meant that your compressor was NOT lossless. It is the reason that the compressor output kept getting smaller as it looped.

    Your decompression function is unfinished, Please stop claiming to have a compressor if you don't have a decompressor.
    But it is very simple to write. Here it is:

        do
    
            chrs = Zlibrary.unpack( chrs )
    
            dim as ubyte top5, bottom3
            dim as ubyte in
            for a as longint = 0 to len( chrs ) - 1  step 1
                in = chrs[a]
                top5 = in shr 3
                bottom3 = in and 7
                chrs[a] = (bottom3 shl 5) or top5
            next
    
            loops -= 1
    
            if loops = 0 then exit do
    
        loop
    

    There are also two other bugs. Firstly you have an extra loops-= 1 above the decompression loop, which I deleted. Secondly, you need to replace
    print #1 , chrs
    with
    put #1, , chrs
    because print adds an extra newline.

    After these fixes, you have a working compressor and decompressor, and it actually outperforms zlib by 0.1% when compressing zlib.dll! Congratulations! Of course, it does not recursely compress any file down to almost nothing, because that is mathematically impossible. But preprocessing the file and then feeding it to zlib to improve the result IS a valid and very successful strategy. Work on that instead.

    I've attached the fixed version of your program, and made it run on Linux as well as Windows. Enjoy!

     

    Last edit: TeeEmCee 2023-05-06
  • TeeEmCee

    TeeEmCee - 2023-05-06

    Opps. I didn't post the actual "fixed" lines of code. I've edited my comment above. They should have been:

            if in >= 192 and in <= 223 then m1 = "6"
            if in >= 224 and in <= 255 then m1 = "7"
    
     
  • Jeff Marshall

    Jeff Marshall - 2023-05-11
    • status: open --> closed
    • assigned_to: Matthew --> nobody
     

Log in to post a comment.