From 72790a51798185cc1fe7cfc3cf11c734b5167cf2 Mon Sep 17 00:00:00 2001 From: Christian Baltzer Date: Tue, 16 Jul 2019 16:23:13 +0200 Subject: [PATCH] =?UTF-8?q?noten=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ugsbo/com/notenSpeicher/Noten.java | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/src/main/java/ugsbo/com/notenSpeicher/Noten.java b/src/main/java/ugsbo/com/notenSpeicher/Noten.java index de5d9ca..48f8874 100644 --- a/src/main/java/ugsbo/com/notenSpeicher/Noten.java +++ b/src/main/java/ugsbo/com/notenSpeicher/Noten.java @@ -1,9 +1,66 @@ package ugsbo.com.notenSpeicher; +import java.security.MessageDigest; + public class Noten { - public Noten() { - // TODO Auto-generated constructor stub + + String Fach; + int Note; + int durchschnitt; + Noten vorher; + + String ownHash; + String previousHash; + + public Noten(String eingabeFach, int eingabeNote) { + Fach = eingabeFach; + Note = eingabeNote; + durchschnitt = eingabeNote; + + vorher = null; + previousHash = null; + + ownHash = createNewHash(eingabeFach); } + private String createNewHash(String input) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + //Applies sha256 to our input, + byte[] hash = digest.digest(input.getBytes("UTF-8")); + StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if(hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + return hexString.toString(); + } + catch(Exception e) { + throw new RuntimeException(e); + } + } + + + public String getFach() { + return Fach; + } + + public int getNote() { + return Note; + } + + public int getDurchschnitt() { + return durchschnitt; + } + + public Noten getVorher() { + return vorher; + } + + public String getOwnHash() { + return ownHash; + } + }