From df10ee4dea63614a1d511e645978d1f39240e565 Mon Sep 17 00:00:00 2001 From: Rohan M Date: Thu, 16 Sep 2021 22:14:03 -0700 Subject: [PATCH 1/2] made a decoder class and updated readme a tiny bit --- .DS_Store | Bin 6148 -> 6148 bytes .classpath | 6 +- .project | 2 +- ReadMe | 4 +- decoded.txt | 1 + src/RohanDecoder.java | 143 ++++++++++++++++++++++++++++++++++++++++++ src/TestLZW.java | 3 + 7 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 decoded.txt create mode 100644 src/RohanDecoder.java diff --git a/.DS_Store b/.DS_Store index 81229e8d26382bd3469cb3d9bb2de3f1954844ac..1d62b9fca9c7c067891dfd12d9b3326dacb235bd 100644 GIT binary patch literal 6148 zcmeHK-HOvd6h70|-BekuAh(CITl54o^(mxBG_KE6{8)%> zQcf9->QRl?tD}N4Kh?Y4x8O96@}k%KE*j0&g{^I?jo*&-%A2I6SNO#=ANtt~u08gP zNubM5(=`55_Je29xIF4yeUK)FA0^{VlA~~pkeAP+BuvX;I!(e{_T#Ar9;bcO*`3Xt zp3}7l&i=e>&+ZO-UE8_i%;#UC2^Xt9_+R7-)B%Zr^(vq=gVKu4=BbqN&)>CSeG_xR%S9r0i(bsD8T!J zjl}3`tQ5+v1DU)609$ZNLs@?O18sHyU5%AOcwjEl=y_$b~*l7=>$3qV(6r4SyN`4EsYn9L~fPZjtD7xJ&! delta 107 zcmZoMXfc=|#>AjHu~68Ak%57MnW31Wh#@&Gr8qe$KR*W~1O`k{8YBS30t`_3&4L_a pESnWLCNXbj=iui6ngkU2&ODi4M3IqkvZ;vjWPcux%`qY?m;oD|6lVYc diff --git a/.classpath b/.classpath index 1cd9d95..0cbf9cd 100644 --- a/.classpath +++ b/.classpath @@ -1,10 +1,6 @@ - - - - - + diff --git a/.project b/.project index 86cd90b..10a5c53 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - LZWCompression + LZW-Compression diff --git a/ReadMe b/ReadMe index 5e46fca..3831e3e 100644 --- a/ReadMe +++ b/ReadMe @@ -5,4 +5,6 @@ uses the method fillInitialValues() to fill the HashMap dict with the pre-determ It then calls the method compress which uses a buffered reader and a for loop to run through each char in the file. It adds combinations of these chars with arbitrary, decimal askii values to dict. The for loop also converts these decimals to binary before adding them to the string binaryString. binaryString is converted into a char array of 0s and 1s, -which is then converted to a byte array, which is then used by the FileOutputStream to write a binary file. \ No newline at end of file +which is then converted to a byte array, which is then used by the FileOutputStream to write a binary file. + +ROHAN: Ariana used 9 bits \ No newline at end of file diff --git a/decoded.txt b/decoded.txt new file mode 100644 index 0000000..a469dd0 --- /dev/null +++ b/decoded.txt @@ -0,0 +1 @@ +Æ888HHH(```d \ No newline at end of file diff --git a/src/RohanDecoder.java b/src/RohanDecoder.java new file mode 100644 index 0000000..1de3419 --- /dev/null +++ b/src/RohanDecoder.java @@ -0,0 +1,143 @@ +import java.util.*; + +import java.io.*; +import java.nio.file.*; + +public class RohanDecoder { + + public HashMap dictionary; + public String binary; + int binaryIndex; + ArrayList numberValues; + + public RohanDecoder() { + binary = ""; + dictionary = new HashMap(); + this.makeDictionary(); + } + + public void makeDictionary() { + for(int i = 0; i<256; i++) { + dictionary.put(i, "" + (char)i); + } + } + + public void ByteToBinary() throws IOException { + FileInputStream input = new FileInputStream("trashbin"); + + binary = ""; + byte[] byteArray = input.readAllBytes(); + //System.out.println(byteArray); + + for(int i =0;i(); + + for(int i = 0;i <= binary.length() - 9; i+=9) { +// System.out.println("next number = " + this.getNextNumberFromBinary()); +// System.out.println("list = " + this.numberValues); + //System.out.println(dictionary.get(this.getNextNumberFromBinary())); + //numberValues.add(getNextNumberFromBinary()); +// if(i+9 > binary.length()) { +// break; +// } + + numberValues.add(binaryToNumber(binary.substring(i,i+9))); + } + } + + public static int binaryToNumber(String a) //found online + { + int ans = 0; + for(int i = 0;i<9;i++) + { + if(a.charAt(i)=='1') + { + ans+=(1<<(8-i)); + } + } + return ans; + } + + + + public String toBinary(int number) + { + String cur =Integer.toBinaryString(number); + StringBuilder ans = new StringBuilder(); + while(cur.length()+ans.length()<8) + { + ans.append("0"); + } + if(cur.length()>8) + { + cur = cur.substring(cur.length()-8); + } + ans.append(cur); + return ans.toString(); + } +} diff --git a/src/TestLZW.java b/src/TestLZW.java index d7a41d3..5fdee2e 100644 --- a/src/TestLZW.java +++ b/src/TestLZW.java @@ -7,5 +7,8 @@ public static void main (String [] args) throws IOException File testFile = new File ("lzw-file1.txt"); LZWCompression compressy= new LZWCompression (testFile); + RohanDecoder decode = new RohanDecoder(); + decode.decode(); + } } From a85a918cf12930ca94ef958ee78084071b63ff6d Mon Sep 17 00:00:00 2001 From: Rohan M Date: Fri, 17 Sep 2021 08:14:50 -0700 Subject: [PATCH 2/2] Updated ReadMe --- ReadMe | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ReadMe b/ReadMe index 3831e3e..ab6c945 100644 --- a/ReadMe +++ b/ReadMe @@ -7,4 +7,7 @@ It adds combinations of these chars with arbitrary, decimal askii values to dict decimals to binary before adding them to the string binaryString. binaryString is converted into a char array of 0s and 1s, which is then converted to a byte array, which is then used by the FileOutputStream to write a binary file. -ROHAN: Ariana used 9 bits \ No newline at end of file +ROHAN: Ariana used 9 bits +The decoder does not work, I am unsure if it is an issue with the decoder or your encoder +It outputs something for file 1, but it is not right +It gets an error for file 3 \ No newline at end of file