Zadananie 3 - CRC #26

Closed
s426271 wants to merge 8 commits from s426271/DALGLI0:zadanie-3 into master
3 changed files with 71 additions and 46 deletions
Showing only changes of commit cdb246b734 - Show all commits

View File

@ -1,14 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="5f8a3521-157f-4adb-a0ab-dc99bbf14aa0" name="Default" comment="small code refactor">
<change afterPath="$PROJECT_DIR$/.idea/description.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/project-template.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/out/production/Zadanie-03/com/tylkowski/crc/CrcTask.class" afterDir="false" />
<change afterPath="$PROJECT_DIR$/out/production/Zadanie-03/com/tylkowski/crc/Main.class" afterDir="false" />
<list default="true" id="5f8a3521-157f-4adb-a0ab-dc99bbf14aa0" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/tylkowski/crc/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/tylkowski/crc/Main.java" afterDir="false" />
</list>
@ -25,8 +19,8 @@
<file leaf-file-name="Main.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="57" selection-start-line="14" selection-start-column="51" selection-end-line="14" selection-end-column="57" />
<state relative-caret-position="255">
<caret line="15" column="9" lean-forward="true" selection-start-line="15" selection-start-column="9" selection-end-line="15" selection-end-column="9" />
</state>
</provider>
</entry>
@ -34,8 +28,8 @@
<file leaf-file-name="CrcTask.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="13" column="22" selection-start-line="13" selection-start-column="22" selection-end-line="13" selection-end-column="22" />
<state relative-caret-position="178">
<caret line="44" column="9" lean-forward="true" selection-start-line="44" selection-start-column="9" selection-end-line="44" selection-end-column="9" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -66,6 +60,9 @@
<find>chunk</find>
<find>toBin</find>
<find>toBinaryStr</find>
<find>swap</find>
<find>letter</find>
<find>lol</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -74,8 +71,8 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java" />
<option value="$PROJECT_DIR$/src/com/tylkowski/crc/Main.java" />
<option value="$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java" />
</list>
</option>
</component>
@ -96,6 +93,8 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="AndroidView" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -118,9 +117,7 @@
<select />
</subPane>
</pane>
<pane id="AndroidView" />
<pane id="Scope" />
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
@ -144,8 +141,7 @@
<configuration name="Main" type="Application" factoryName="Application" temporary="true">
<option name="MAIN_CLASS_NAME" value="com.tylkowski.crc.Main" />
<module name="Zadanie-03" />
<option name="PROGRAM_PARAMETERS" value="&quot;1&quot; &quot;a&quot;" />
<option name="VM_PARAMETERS" value="-Dfile.encoding=latin-1" />
<option name="PROGRAM_PARAMETERS" value="&quot;2&quot; &quot;b­&quot;" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Run" />
@ -187,7 +183,8 @@
<workItem from="1529407679397" duration="19000" />
<workItem from="1529409635196" duration="1437000" />
<workItem from="1529428699866" duration="20522000" />
<workItem from="1529482084631" duration="5516000" />
<workItem from="1529482084631" duration="5831000" />
<workItem from="1529497353540" duration="2850000" />
</task>
<task id="LOCAL-00001" summary="project started">
<created>1529359475020</created>
@ -224,11 +221,18 @@
<option name="project" value="LOCAL" />
<updated>1529450003665</updated>
</task>
<option name="localTasksCounter" value="6" />
<task id="LOCAL-00006" summary="charset update">
<created>1529487959831</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1529487959831</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="41722000" />
<option name="totallyTimeSpent" value="44887000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
@ -244,11 +248,11 @@
<window_info anchor="right" id="Maven Projects" order="3" />
<window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.43069306" />
<window_info anchor="bottom" id="Run" order="2" weight="0.38118812" />
<window_info anchor="bottom" id="Terminal" order="7" />
<window_info id="Capture Tool" order="2" />
<window_info id="Designer" order="2" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.16414523" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.16641453" />
<window_info anchor="right" id="Database" order="3" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
@ -276,9 +280,27 @@
<MESSAGE value="encode added!" />
<MESSAGE value="decode added!" />
<MESSAGE value="small code refactor" />
<option name="LAST_COMMIT_MESSAGE" value="small code refactor" />
<MESSAGE value="charset update" />
<option name="LAST_COMMIT_MESSAGE" value="charset update" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<caret line="22" lean-forward="true" selection-start-line="22" selection-end-line="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2856">
<caret line="170" selection-start-line="170" selection-end-line="170" selection-end-column="50" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
@ -366,10 +388,24 @@
</state>
</provider>
</entry>
<entry file="jar://C:/Program Files/Java/jdk1.8.0_77/src.zip!/java/lang/System.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="329">
<caret line="494" column="24" selection-start-line="494" selection-start-column="24" selection-end-line="494" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="jar://C:/Program Files/Java/jdk1.8.0_77/src.zip!/java/util/Arrays.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="278">
<caret line="3556" column="19" selection-start-line="3556" selection-start-column="19" selection-end-line="3556" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/CrcTask.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="13" column="22" selection-start-line="13" selection-start-column="22" selection-end-line="13" selection-end-column="22" />
<state relative-caret-position="178">
<caret line="44" column="9" lean-forward="true" selection-start-line="44" selection-start-column="9" selection-end-line="44" selection-end-column="9" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -378,8 +414,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/src/com/tylkowski/crc/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="57" selection-start-line="14" selection-start-column="51" selection-end-line="14" selection-end-column="57" />
<state relative-caret-position="255">
<caret line="15" column="9" lean-forward="true" selection-start-line="15" selection-start-column="9" selection-end-line="15" selection-end-column="9" />
</state>
</provider>
</entry>

View File

@ -65,8 +65,6 @@ class CrcTask {
remainder = removeUnecessaryZeros(remainder);
messageAsShortArray = createMessageFromRemainderAndPartFromOldMessage(remainder, messageAsShortArray);
}
}
}
@ -111,7 +109,6 @@ class CrcTask {
private char getCharFromShortArray(short[] piece, int from, int to) {
short[] sign = Arrays.copyOfRange(piece, from, to);
int character = Integer.parseInt(shortArrayToBinaryString(sign), 2);
// System.out.println(character);
return (char) character;
}
@ -165,30 +162,23 @@ class CrcTask {
}
private String letterToBinaryString(char letter) {
// System.out.println("lt: " + letter + " " + (int) letter);
int a = (int) letter;
// if (a == 63) a = 157;
System.out.println("letter in int: " + a);
StringBuilder binaryString = new StringBuilder(Integer.toBinaryString(a));
while (binaryString.length() % 8 != 0) {
binaryString.insert(0, "0");
}
// System.out.println("bs" + binaryString.toString());
return binaryString.toString();
}
boolean decode(String encodedString) {
encodedString = toBinaryString(encodedString);
encodedString = fillPolyTo8(encodedString);
encodedString = fillPoly(encodedString);
short[] encodedShortArray = convertBinaryStringToShortArray(encodedString);
encodedShortArray = swapPolynomialValues(encodedShortArray);
while (true) {
if (!shortArrayContains(encodedShortArray, 1)) {
return true;
}
if (encodedShortArray[0] == 0) {
encodedShortArray = Arrays.copyOfRange(encodedShortArray, 1, encodedShortArray.length);
} else {
@ -208,7 +198,6 @@ class CrcTask {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < encodedString.length(); i++) {
stringBuilder.append(letterToBinaryString(encodedString.charAt(i)));
}
return stringBuilder.toString();
}
@ -222,7 +211,7 @@ class CrcTask {
return false;
}
private String fillPolyTo8(String encodedString) {
private String fillPoly(String encodedString) {
StringBuilder stringBuilder = new StringBuilder(encodedString);
while (stringBuilder.length() % 8 != 0) {
stringBuilder.insert(0, "0");

View File

@ -3,10 +3,10 @@ package com.tylkowski.crc;
public class Main {
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
// use valid character encoding ISO-8859-1
// in command line type "1" for mode and "a" for message
//example "1" "a" -> this will encode string "a" and return FCS
// example "2" "abc" -> this will decode string "abc" and return true if it is valid or false if not
// in command line type "1" for mode and "b" for message
// example "1" "b" -> this will encode string "b" and return FCS
// example "2" "bXY" -> this will decode string "bXY" and return true if it is valid or false if not
// X and Y - 1 and 2 character of FCS
CrcTask crcTask = new CrcTask(args[1], args[1]);
if(args[0].equals("1")) {
//create FCS