Jump to content

[fixed]


Recommended Posts

Sooo, I had a good idea a few days ago for a custom compression method. It's really simple and I'm sure alot of people have thought up of this before... All it does is searches for more then one copy of 4 char ... which it then replaces it with one character... now assuming I didn't do anything wrong this should decrese the file big time... but I most likely did something wrong since it tends to double in size :oops:

Here's my code

#include <string.au3>
Opt("MustDeclareVars", 1)
FileDelete(@ScriptDir & "\compression-log.txt")
Global $m_file, $f_read, $f_Lenth, $r_chars, $c_save
Global $count = 0
Global $symbols = ""
$m_file = FileOpen(@ScriptDir & "\test.exe", 16)
$f_read = FileRead($m_file)
$c_save = $f_read
ProgressOn("Searching", "Searching for matches")
$f_Lenth = StringLen($f_read)
Do
local $x, $y, $z, $a
$x = read_Chars()
$y = $count / StringLen($f_read) * 100
ProgressSet($y)
$z = StringInStr($f_read, $x, 0, 2)
If $z <> 0 Then
  $a = set_Symbol()
  $c_save = StringReplace($c_save, $x, "-" & $a & "-")
  $f_read = StringReplace($f_read, $x, "")
  log_To_File("Match found using: " & $x & " compressing using " & $a)
Else
  log_To_File("Searching for matches using: " & $x)
EndIf
Until $count >= StringLen($f_read)
FileClose($m_file)
ProgressOff()
Msgbox(64, "Search is done", "Search has been completed" & @CRLF & "Compressed to " & StringLen($c_save) & " bytes")
Func read_Chars()
If $count == 0 Then
  $r_chars = StringLeft($f_read, 4)
Else
  $r_chars = StringMid($f_read, $count, 4)
EndIf
$count = $count + 5
Return $r_chars
EndFunc
Func log_To_File($data)
Local $file
$file = FileOpen(@ScriptDir & "\compression-log.txt", 1)
FileWrite($file, $data & @CRLF)
FileClose($file)
EndFunc
Func record_Match($match, $data)
local $file = @ScriptDir & "\temp.ini"
;IniRead($file, Found
EndFunc
Func set_Symbol()
local $ran, $search, $x, $y = False
While $y = False
$ran = Random(1000, 9999)
$ran = Round($ran)
$ran = ChrW($ran)
$x = StringInStr($symbols, $ran)
If $x == 0 Then
  $symbols = $symbols & $ran & ","
  Return $ran
  $y = True
Else
  log_To_File("Key already in use")
EndIf
WEnd
Return $ran
EndFunc

Turns out binary is bigger then file contents themself

Edited by SleeperCell42
Link to comment
Share on other sites

  • Moderators

SleeperCell42,

Please do not remove the title of your thread as it then cannot help anyone who searches for threads on the same problem later - just add [Fixed] if you so wish. And if you fixed it, it would be kind to post the solution for the same reason. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...