Ultra Geile Studenten Benutzer Oberfläche (UGSBO)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. package ugsbo.com.notenSpeicher;
  2. import java.security.MessageDigest;
  3. public class Noten {
  4. String Fach;
  5. int Note;
  6. int durchschnitt;
  7. Noten vorher;
  8. String ownHash;
  9. String previousHash;
  10. public Noten(String eingabeFach, int eingabeNote) {
  11. Fach = eingabeFach;
  12. Note = eingabeNote;
  13. durchschnitt = eingabeNote;
  14. vorher = null;
  15. previousHash = null;
  16. ownHash = createNewHash(eingabeFach);
  17. }
  18. private String createNewHash(String input) {
  19. try {
  20. MessageDigest digest = MessageDigest.getInstance("SHA-256");
  21. //Applies sha256 to our input,
  22. byte[] hash = digest.digest(input.getBytes("UTF-8"));
  23. StringBuffer hexString = new StringBuffer(); // This will contain hash as hexidecimal
  24. for (int i = 0; i < hash.length; i++) {
  25. String hex = Integer.toHexString(0xff & hash[i]);
  26. if(hex.length() == 1) hexString.append('0');
  27. hexString.append(hex);
  28. }
  29. return hexString.toString();
  30. }
  31. catch(Exception e) {
  32. throw new RuntimeException(e);
  33. }
  34. }
  35. public String getFach() {
  36. return Fach;
  37. }
  38. public int getNote() {
  39. return Note;
  40. }
  41. public int getDurchschnitt() {
  42. return durchschnitt;
  43. }
  44. public Noten getVorher() {
  45. return vorher;
  46. }
  47. public String getOwnHash() {
  48. return ownHash;
  49. }
  50. }