Übersetzen Python --> Java

andreas2505

Bekanntes Mitglied
Hallo,

ich habe hier eine Methode, die ich dringend benötige, allerdings in Java und nicht in Python.
Kann mir vielleicht jemand die Methode übersetzen. Hab schon angefangen, aber es hängt jetzt und ich kann mir nicht mehr die Befehle erklären.

Hier die Methode in Python:

Code:
def pad10star1(self, M, n):
        """Pad M with the pad10*1 padding rule to reach a length multiple of r bits

        M: message pair (length in bits, string of hex characters ('9AFC...')
        n: length in bits (must be a multiple of 8)
        Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns 'BA594E0FB9EBBD93'
        """

        [my_string_length, my_string]=M

        # Check the parameter n
        if n%8!=0:
            raise KeccakError.KeccakError("n must be a multiple of 8")

        # Check the length of the provided string
        if len(my_string)%2!=0:
            #Pad with one '0' to reach correct length (don't know test
            #vectors coding)
            my_string=my_string+'0'
        if my_string_length>(len(my_string)//2*8):
            raise KeccakError.KeccakError("the string is too short to contain the number of bits announced")

        nr_bytes_filled=my_string_length//8
        nbr_bits_filled=my_string_length%8
        l = my_string_length % n
        if ((n-8) <= l <= (n-2)):
            if (nbr_bits_filled == 0):
                my_byte = 0
            else:
                my_byte=int(my_string[nr_bytes_filled*2:nr_bytes_filled*2+2],16)
            my_byte=(my_byte>>(8-nbr_bits_filled))
            my_byte=my_byte+2**(nbr_bits_filled)+2**7
            my_byte="%02X" % my_byte
            my_string=my_string[0:nr_bytes_filled*2]+my_byte
        else:
            if (nbr_bits_filled == 0):
                my_byte = 0
            else:
                my_byte=int(my_string[nr_bytes_filled*2:nr_bytes_filled*2+2],16)
            my_byte=(my_byte>>(8-nbr_bits_filled))
            my_byte=my_byte+2**(nbr_bits_filled)
            my_byte="%02X" % my_byte
            my_string=my_string[0:nr_bytes_filled*2]+my_byte
            while((8*len(my_string)//2)%n < (n-8)):
                my_string=my_string+'00'
            my_string = my_string+'80'

        return my_string

und hier mein Anfang:

Java:
public byte[] pad10star1(byte[] M, int my_string_length, int n) {
        
        //Padded die Nachricht M, so dass eine vielfache Länge von r erreicht wird

        //M: message pair (length in bits, string of hex characters ('9AFC...')
        //n: length in bits (must be a multiple of 8)
        //Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns 'BA594E0FB9EBBD93'
      
        
        byte[] my_string = M;

        if (n % 8 !=0)
            throw new RuntimeException("n must be a multiple of 8");
        
        // Check the length of the provided string
        if (my_string.length % 2 !=0) {
            //Pad with one '0' to reach correct length (don't know test
            //vectors coding)
            byte[] x = new byte[]{(byte) 0x00};
            my_string = Help.anhaengen(my_string, x, my_string.length, 1);
        }
        
        if (my_string_length > my_string.length/2*8) {
            throw new RuntimeException("the string is too short to contain the number of bits announced");}
            

        int nr_bytes_filled = my_string_length/8;
        int nbr_bits_filled = my_string_length % 8;
        int l = my_string_length % n;
        
        int my_byte;
        
        if ((n-8) <= l && l <= (n-2)){
            if (nbr_bits_filled == 0) {
                my_byte = 0;}
 

andreas2505

Bekanntes Mitglied
Das hört sich interessant an, allerdings ist mir das alles sehr unübersichtlich und ich verstehe nicht, was ich wirklich brauche und was ich implementieren muss.

Kannst du mir vielleicht das schreiben, was ich für meinen Fall benötige. Also ich will die eine Methode von Python in Java anwenden können. Was muss ich dazu alles machen?
 
T

Tomate_Salat

Gast
Du schreibst dir ein Interface, welches die Methoden kennt, die das Python-Script auch hat (gleiche namen, gleiche Parameter). Versuche einfach mal mein kleines Tutorial nachzubauen + verstehen. Bei unklarheiten, kannst du auch gerne hier fragen.
 

Ariol

Top Contributor
Wie immer ohne Gewähr. Beispiel klappt ;-).
Java:
public class Test
{
	public static void main(String[] args)
	{
		byte[] in_60 = new byte[60];
		System.arraycopy(new byte[]{'B','A','5','9','4','E','0','F','B','9','E','B','B','D','3','0'}, 0, in_60, 0, 16);
		byte[] test = pad10star1(in_60, 8);
		System.out.println(new String(test));
		return;
	}
	
	public static byte[] pad10star1(byte[] M, int n) {
        
        //Padded die Nachricht M, so dass eine vielfache Länge von r erreicht wird
 
        //M: message pair (length in bits, string of hex characters ('9AFC...')
        //n: length in bits (must be a multiple of 8)
        //Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns 'BA594E0FB9EBBD93'
		byte[] my_string=M;
		int my_string_length=M.length;
		
         
        if (n % 8 !=0)
            throw new RuntimeException("n must be a multiple of 8");
        
        // Check the length of the provided string
        if (my_string.length % 2 !=0) {
            //Pad with one '0' to reach correct length (don't know test
            //vectors coding)
        	my_string=new byte[my_string_length+1];
        	System.arraycopy(M, 0, my_string, 0, M.length);
        	my_string[my_string_length]='0';
        	                   
        }
        
        if (my_string_length > my_string.length/2*8) {
            throw new RuntimeException("the string is too short to contain the number of bits announced");}
            
 
        int nr_bytes_filled = my_string_length/8;
        int nbr_bits_filled = my_string_length % 8;
        int l = my_string_length % n;
        
        int my_byte;
        
        if ((n-8) <= l && l <= (n-2))
        {
            if (nbr_bits_filled == 0)
            {
                my_byte = 0;
            }
            else
            {
            	byte[] bytes = new byte[2];
            	System.arraycopy(my_string, nr_bytes_filled*2, bytes, 0, bytes.length);
            	my_byte=Integer.parseInt(new String(bytes),16);
            }
            my_byte=(my_byte>>(8-nbr_bits_filled));
            my_byte=my_byte+(1<<(nbr_bits_filled))+(1<<7);
            byte[] bytes = Integer.toString(my_byte, 16).getBytes();
            byte[] temp = new byte[nr_bytes_filled*2+2];
            System.arraycopy(my_string, 0, temp, 0, nr_bytes_filled*2);
        	System.arraycopy(bytes, 0, temp, nr_bytes_filled*2, 2);
        	
        	my_string=temp.clone();
        }
        else
        {
        	if (nbr_bits_filled == 0)
            {
                my_byte = 0;
            }
            else
            {
            	byte[] bytes = new byte[2];
            	System.arraycopy(my_string, nr_bytes_filled*2, bytes, 0, bytes.length);
            	my_byte=Integer.parseInt(new String(bytes),16);
            }
        	my_byte=(my_byte>>(8-nbr_bits_filled));
            my_byte=my_byte+(1<<(nbr_bits_filled));
            byte[] bytes = Integer.toString(my_byte, 16).getBytes();
            byte[] temp = new byte[nr_bytes_filled*2+2];
            System.arraycopy(my_string, 0, temp, 0, nr_bytes_filled*2);
        	System.arraycopy(bytes, 0, temp, nr_bytes_filled*2, 2);
        	
        	int newSize = temp.length;        	
            while((8*newSize/2)%n < (n-8))
            {
            	newSize+=2;
            }
            newSize+=2;
            my_string=new byte[newSize];
            
            System.arraycopy(temp, 0, my_string, 0, temp.length);
            my_string[newSize-2]='8';
        }
        return my_string;
	}
	
}
 

andreas2505

Bekanntes Mitglied
Hallo, danke für dein Posting.

Habs mal ausprobiert, es funzt zwar für den Wert, aber nicht für andere:

Bsp.: aus "53587BC8" muss folgendes werden:

53 58 7B 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80

dafür müsste dann n 104 sein!!!

Dann kommt aber in Zeile 78 ne NumberFormatException.

Irgendwie haut das da nicht hin. Geht das parsen überhaupt bei hexamdezimalen Werten?
Verstehe sowieso nicht so ganz, wie du von dem Python auf diese Schleife kommst...
Warum ist das dann ein byte-array mit der Länge 3?

Vielleicht kannste ja an dem Beispiel den Fehler finden...
Ich finde ihn leider nicht
 

Ariol

Top Contributor
Versuchs doch mal so:
Java:
	byte[] in = new byte[] { '5', '3', '5', '8', '7', 'B', 'C', '8' };
	byte[] in_104 = new byte[104];
	for(int i = 0; i < in_104.length; i++)
		in_104[i]='0';
	System.arraycopy(in, 0, in_104, 0, in.length);
	byte[] test = pad10star1(in_104, 8);
	System.out.println(new String(test));

EDIT:
n von 60 auf 104 geändert.
Ausgabe:
Code:
53587BC800000000000000000081
 

andreas2505

Bekanntes Mitglied
Java:
byte[] in_104 = new byte[104];
warum machst du vorher ein Array mit 104 Stellen. Dann sind die ja automatisch mit 0 initalisiert.
was du ja dann in der nächsten Zeile nochmal machst. Das ist ja irgendwie komisch. Was soll das denn bringen? Und was soll danach die Zeile?

Java:
byte[] test = pad10star1(in_104, 8);
Die Funktion muss aufgerufen werden mit n = 104 und nicht mit n=8. n muss variabel sein und in diesem Fall 104 und dann muss der oben angegebene Wert rauskommen.

EDIT: Falls es nicht klappt, könnte es auch noch an zwei verschiedenen Dingen liegen:

1. Ist denn in dieser Methode der Fall geklärt, falls die Länge des Inputs, als von M kein Vielfaches von 8 bits ist. In diesem Fall ist es nämlich 29 bits lang und damit müsste noch zwischen MSB und LSB unterschieden werden, bei Eingaben, deren Länge nicht Vielfaches von 8 ist.
Mit LSB wäre die Nachricht dann "53587B19" (habe die Werte auch nur von einer fertigen Seite)

2. Das 2. Problem könnte sein, dass später noch irgendein Wert angefügt wird, weil da im Python Algorithmus nach Aufruf dieser Methode noch steht:

Code:
#Padding of messages
        P = self.pad10star1(M, r)

        if verbose:
            print("String ready to be absorbed: %s (will be completed by %d x '00')" % (P, c//8))
 
Zuletzt bearbeitet:

Ariol

Top Contributor
Das array war mit 0='\0' initialisiert nicht '0'.

Mir sind noch andere Probleme aufgefallen und ich hab jetzt einfach mal die Datentypen geändert.
Der Code ist auch gleich viel übersichtlicher.

Leider fehlt mir zum Testen das m für deinen 2ten String. (Beim ersten wars 60)
Wenn du mir sagst wie man das errechnen kann, rüste ich das auch nach :wink:

Java:
import java.io.IOException;

public class Test
{
	public static void main(String[] args) throws IOException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException
	{
		int m = 16;
		int n = 104;
		String M = "53587BC8";
		System.out.println(pad10star1(m, M, n));

	}

	public static String pad10star1(int m, String M, int n)
	{
		 //Padded die Nachricht M, so dass eine vielfache Länge von r erreicht wird
		 
        //M: message pair (length in bits, string of hex characters ('9AFC...')
        //n: length in bits (must be a multiple of 8)
        //Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns 'BA594E0FB9EBBD93'
        int my_string_length=m;
        String my_string=M;
        
         
        if (n % 8 !=0)
            throw new RuntimeException("n must be a multiple of 8");
        
		// Check the length of the provided string
		if (my_string.length() % 2 != 0)
		{
			// Pad with one '0' to reach correct length (don't know test vectors coding)
			my_string+='0';

		}

		if (my_string_length > my_string.length() / 2 * 8)
		{
			throw new RuntimeException("the string is too short to contain the number of bits announced");
		}

		int nr_bytes_filled = my_string_length / 8;
		int nbr_bits_filled = my_string_length % 8;
		int l = my_string_length % n;

		int my_byte;

		if ((n - 8) <= l && l <= (n - 2))
		{
			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} 
			else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2+2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled)) + (1 << 7);
            my_string=String.format("%s%02x",my_string.substring(0,nr_bytes_filled*2),my_byte);
		} else
		{
			
			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} 
			else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2+2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled));
            my_string=String.format("%s%02x",my_string.substring(0,nr_bytes_filled*2),my_byte);
			while ((8 * my_string.length() / 2) % n < (n - 8))
			{
				my_string+="00";
			}
			my_string+="80";
		}
		return my_string;
	}
}
 

andreas2505

Bekanntes Mitglied
das ist eine gute Frage, ich weiß selber nicht, wie die darauf kommen...

Kann man das vielleicht von dem 1. Beispiel nachvollziehen. Welche Wirkung hat es denn, vielleicht kann ich es dann rausfinden, was es sein könnte...
 

Ariol

Top Contributor
Hmm, sieht nach einer Art "Anzahl der Bits aus".
Stimmt aber nicht ganz. Im ersten Fall müsste sonst 64 übergeben werden.

Also eventuell
Code:
n=(M.length-1)/4
?

Noch was:
Ersetze doch bitte die beiden Stellen
Code:
"%s%02x"
durch
Code:
"%s%02X"
.
Das sieht einheitlicher aus :wink:

EDIT: Steht auch so im Kommentar. n=Anzahl Bits.
Wie da jetzt 60 rauskommen soll ist mir immer noch schleierhaft. Zumal ja sowieso im Code auf Byte gepadded wird. n müsste von daher ein Vielfaches von 8 sein.



EDIT2:
...
53 58 7B 39 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80
...
Das ist viel zu groß. Es geht hier um die Anzahl der Bits. Alleine "7B" ist schon 8 Bit groß.
Bei n=104 bekommst du also einen String mit 26 Stellen.

Das hier kommt bei der aktuellen Version raus:
Code:
	int n = 104;
	String M = "53587BC8";
	int m = (M.length()-1)*4;

	Ausgabe=53587B1C000000000000000080

26 Stellen :wink:
 
Zuletzt bearbeitet:

Ariol

Top Contributor
Auf die Gefahr hin, dass das so stimmt:

Java:
import java.io.IOException;

public class Test
{
	public static void main(String[] args) throws IOException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException
	{
		System.out.println(pad10star1("BA594E0FB9EBBD30", 8));
		System.out.println(pad10star1("53587BC8",104));

	}

	public static String pad10star1(String M, int n)
	{
		 //Padded die Nachricht M, so dass eine vielfache Länge von r erreicht wird
		 
        //M: message pair (length in bits, string of hex characters ('9AFC...')
        //n: length in bits (must be a multiple of 8)
        //Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns 'BA594E0FB9EBBD93'
        int my_string_length=(M.length()-1)*4;
        String my_string=M;
        
         
        if (n % 8 !=0)
            throw new RuntimeException("n must be a multiple of 8");
        
		// Check the length of the provided string
		if (my_string.length() % 2 != 0)
		{
			// Pad with one '0' to reach correct length (don't know test vectors coding)
			my_string+='0';

		}

		if (my_string_length > my_string.length() / 2 * 8)
		{
			throw new RuntimeException("the string is too short to contain the number of bits announced");
		}

		int nr_bytes_filled = my_string_length / 8;
		int nbr_bits_filled = my_string_length % 8;
		int l = my_string_length % n;

		int my_byte;

		if ((n - 8) <= l && l <= (n - 2))
		{
			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} 
			else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2+2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled)) + (1 << 7);
            my_string=String.format("%s%02X",my_string.substring(0,nr_bytes_filled*2),my_byte);
		} else
		{
			
			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} 
			else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2+2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled));
            my_string=String.format("%s%02X",my_string.substring(0,nr_bytes_filled*2),my_byte);
			while ((8 * my_string.length() / 2) % n < (n - 8))
			{
				my_string+="00";
			}
			my_string+="80";
		}
		return my_string;
	}
}
 

andreas2505

Bekanntes Mitglied
also irgendwie weiß ich gar nicht, was welche Länge ist...

M ist die Nachricht
m ist die Länge von M (denk ich mal)
und meiner Meinung nach ist n die Länge in Bytes von dem was rauskommen soll, also wie groß der String dann sein soll (hätte ich jetzt mal gesagt)

Damit für diesen Fall m=16, n=104

So kommt kein Fehler raus, aber auch nich der richtige Wert

EDIT:

Die Kommentare waren noch zu der letzten Version

Zu der neuen:

Irgendwie kann es aber auch nicht stimmen, weil es kommt ja nicht das richtige raus.
Glaub mir es muss da irgendwie so ein langer Wert rauskommen.
Es steht ja auch in der Beschreibung, dass es eine Vielfache des Wertes r als Länge haben soll. Und r ist in diesem Fall 832 bits, also 104 bytes!
Irgendwas muss da noch gehen...
 
Zuletzt bearbeitet:

andreas2505

Bekanntes Mitglied
der Zielwert stammt von der Entwicklerseite des Programms, also der Stimmt auch! Und der Wert für r ist da auch vorgegeben, also für das Beispiel, und deswegen muss da so ein langer Wert rauskommen.

ich poste dir hier nochmal den kompletten Code von Python.
Relevant sind eigentlich nur die Methoden def pad10star1(self, M, n), die wir die ganze Zeit bearbeiten und def Keccak(self,M,r=1024,c=576,n=1024,verbose=False)
nicht täuschen lassen dass hier r=1024 ist, das sind die default Werte. Für unser Beispiel ist r=832 (in bits)

also in die def Keccak wird praktisch der M Wert eingegeben, dann ein bisschen initialisiert, usw. und dann wird die def pad10star1 aufgerufen.
Ich markiere dir mal rot, an welcher Stelle der lange Wert berechnet wurde auf den wir nicht kommen
(er nennt sich auch block to be absorbed, deshalb wirds die Stelle sein)

ok ich hoffe mal du kannst mir jetzt vielleicht noch ein bisschen mehr helfen :oops:

Code:
import math

class KeccakError(Exception):
    """Class of error used in the Keccak implementation

    Use: raise KeccakError.KeccakError("Text to be displayed")"""

    def __init__(self, value):
        self.value = value
    def __str__(self):
        return repr(self.value)


class Keccak:
    """
    Class implementing the Keccak sponge function
    """
    def __init__(self, b=1600):
        """Constructor:

        b: parameter b, must be 25, 50, 100, 200, 400, 800 or 1600 (default value)"""
        self.setB(b)

    def setB(self,b):
        """Set the value of the parameter b (and thus w,l and nr)

        b: parameter b, must be choosen among [25, 50, 100, 200, 400, 800, 1600]
        """

        if b not in [25, 50, 100, 200, 400, 800, 1600]:
            raise KeccakError.KeccakError('b value not supported - use 25, 50, 100, 200, 400, 800 or 1600')

        # Update all the parameters based on the used value of b
        self.b=b
        self.w=b//25
        self.l=int(math.log(self.w,2))
        self.nr=12+2*self.l

    # Constants

    ## Round constants
    RC=[0x0000000000000001,
        0x0000000000008082,
        0x800000000000808A,
        0x8000000080008000,
        0x000000000000808B,
        0x0000000080000001,
        0x8000000080008081,
        0x8000000000008009,
        0x000000000000008A,
        0x0000000000000088,
        0x0000000080008009,
        0x000000008000000A,
        0x000000008000808B,
        0x800000000000008B,
        0x8000000000008089,
        0x8000000000008003,
        0x8000000000008002,
        0x8000000000000080,
        0x000000000000800A,
        0x800000008000000A,
        0x8000000080008081,
        0x8000000000008080,
        0x0000000080000001,
        0x8000000080008008]

    ## Rotation offsets
    r=[[0,    36,     3,    41,    18]    ,
       [1,    44,    10,    45,     2]    ,
       [62,    6,    43,    15,    61]    ,
       [28,   55,    25,    21,    56]    ,
       [27,   20,    39,     8,    14]    ]

    ## Generic utility functions

    def rot(self,x,n):
        """Bitwise rotation (to the left) of n bits considering the \
        string of bits is w bits long"""

        n = n%self.w
        return ((x>>(self.w-n))+(x<<n))%(1<<self.w)

    def fromHexStringToLane(self, string):
        """Convert a string of bytes written in hexadecimal to a lane value"""

        #Check that the string has an even number of characters i.e. whole number of bytes
        if len(string)%2!=0:
            raise KeccakError.KeccakError("The provided string does not end with a full byte")

        #Perform the modification
        temp=''
        nrBytes=len(string)//2
        for i in range(nrBytes):
            offset=(nrBytes-i-1)*2
            temp+=string[offset:offset+2]
        return int(temp, 16)

    def fromLaneToHexString(self, lane):
        """Convert a lane value to a string of bytes written in hexadecimal"""

        laneHexBE = (("%%0%dX" % (self.w//4)) % lane)
        #Perform the modification
        temp=''
        nrBytes=len(laneHexBE)//2
        for i in range(nrBytes):
            offset=(nrBytes-i-1)*2
            temp+=laneHexBE[offset:offset+2]
        return temp.upper()

    def printState(self, state, info):
        """Print on screen the state of the sponge function preceded by \
        string info

        state: state of the sponge function
        info: a string of characters used as identifier"""

        print("Current value of state: %s" % (info))
        for y in range(5):
            line=[]
            for x in range(5):
                 line.append(hex(state[x][y]))
            print('\t%s' % line)

    ### Conversion functions String <-> Table (and vice-versa)

    def convertStrToTable(self,string):
        """Convert a string of bytes to its 5×5 matrix representation

        string: string of bytes of hex-coded bytes (e.g. '9A2C...')"""

        #Check that input paramaters
        if self.w%8!= 0:
            raise KeccakError("w is not a multiple of 8")
        if len(string)!=2*(self.b)//8:
            raise KeccakError.KeccakError("string can't be divided in 25 blocks of w bits\
            i.e. string must have exactly b bits")

        #Convert
        output=[[0,0,0,0,0],
                [0,0,0,0,0],
                [0,0,0,0,0],
                [0,0,0,0,0],
                [0,0,0,0,0]]
        for x in range(5):
            for y in range(5):
                offset=2*((5*y+x)*self.w)//8
                output[x][y]=self.fromHexStringToLane(string[offset:offset+(2*self.w//8)])
        return output

    def convertTableToStr(self,table):
        """Convert a 5×5 matrix representation to its string representation"""

        #Check input format
        if self.w%8!= 0:
            raise KeccakError.KeccakError("w is not a multiple of 8")
        if (len(table)!=5) or (False in [len(row)==5 for row in table]):
            raise KeccakError.KeccakError("table must be 5×5")

        #Convert
        output=['']*25
        for x in range(5):
            for y in range(5):
                output[5*y+x]=self.fromLaneToHexString(table[x][y])
        output =''.join(output).upper()
        return output

    def Round(self,A,RCfixed):
        """Perform one round of computation as defined in the Keccak-f permutation

        A: current state (5×5 matrix)
        RCfixed: value of round constant to use (integer)
        """

        #Initialisation of temporary variables
        B=[[0,0,0,0,0],
           [0,0,0,0,0],
           [0,0,0,0,0],
           [0,0,0,0,0],
           [0,0,0,0,0]]
        C= [0,0,0,0,0]
        D= [0,0,0,0,0]

        #Theta step
        for x in range(5):
            C[x] = A[x][0]^A[x][1]^A[x][2]^A[x][3]^A[x][4]

        for x in range(5):
            D[x] = C[(x-1)%5]^self.rot(C[(x+1)%5],1)

        for x in range(5):
            for y in range(5):
                A[x][y] = A[x][y]^D[x]

        #Rho and Pi steps
        for x in range(5):
          for y in range(5):
                B[y][(2*x+3*y)%5] = self.rot(A[x][y], self.r[x][y])

        #Chi step
        for x in range(5):
            for y in range(5):
                A[x][y] = B[x][y]^((~B[(x+1)%5][y]) & B[(x+2)%5][y])

        #Iota step
        A[0][0] = A[0][0]^RCfixed

        return A

    def KeccakF(self,A, verbose=False):
        """Perform Keccak-f function on the state A

        A: 5×5 matrix containing the state
        verbose: a boolean flag activating the printing of intermediate computations
        """

        if verbose:
            self.printState(A,"Before first round")

        for i in range(self.nr):
            #NB: result is truncated to lane size
            A = self.Round(A,self.RC[i]%(1<<self.w))

            if verbose:
                  self.printState(A,"Satus end of round #%d/%d" % (i+1,self.nr))

        return A

    ### Padding rule

    def pad10star1(self, M, n):
        """Pad M with the pad10*1 padding rule to reach a length multiple of r bits

        M: message pair (length in bits, string of hex characters ('9AFC...')
        n: length in bits (must be a multiple of 8)
        Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns 'BA594E0FB9EBBD93'
        """

        [my_string_length, my_string]=M

        # Check the parameter n
        if n%8!=0:
            raise KeccakError.KeccakError("n must be a multiple of 8")

        # Check the length of the provided string
        if len(my_string)%2!=0:
            #Pad with one '0' to reach correct length (don't know test
            #vectors coding)
            my_string=my_string+'0'
        if my_string_length>(len(my_string)//2*8):
            raise KeccakError.KeccakError("the string is too short to contain the number of bits announced")

        nr_bytes_filled=my_string_length//8
        nbr_bits_filled=my_string_length%8
        l = my_string_length % n
        if ((n-8) <= l <= (n-2)):
            if (nbr_bits_filled == 0):
                my_byte = 0
            else:
                my_byte=int(my_string[nr_bytes_filled*2:nr_bytes_filled*2+2],16)
            my_byte=(my_byte>>(8-nbr_bits_filled))
            my_byte=my_byte+2**(nbr_bits_filled)+2**7
            my_byte="%02X" % my_byte
            my_string=my_string[0:nr_bytes_filled*2]+my_byte
        else:
            if (nbr_bits_filled == 0):
                my_byte = 0
            else:
                my_byte=int(my_string[nr_bytes_filled*2:nr_bytes_filled*2+2],16)
            my_byte=(my_byte>>(8-nbr_bits_filled))
            my_byte=my_byte+2**(nbr_bits_filled)
            my_byte="%02X" % my_byte
            my_string=my_string[0:nr_bytes_filled*2]+my_byte
            while((8*len(my_string)//2)%n < (n-8)):
                my_string=my_string+'00'
            my_string = my_string+'80'

        return my_string

    def Keccak(self,M,r=1024,c=576,n=1024,verbose=False):
        """Compute the Keccak[r,c,d] sponge function on message M

        M: message pair (length in bits, string of hex characters ('9AFC...')
        r: bitrate in bits (defautl: 1024)
        c: capacity in bits (default: 576)
        n: length of output in bits (default: 1024),
        verbose: print the details of computations(default:False)
        """

        #Check the inputs
        if (r<0) or (r%8!=0):
            raise KeccakError.KeccakError('r must be a multiple of 8 in this implementation')
        if (n%8!=0):
            raise KeccakError.KeccakError('outputLength must be a multiple of 8')
        self.setB(r+c)

        if verbose:
            print("Create a Keccak function with (r=%d, c=%d (i.e. w=%d))" % (r,c,(r+c)//25))

        #Compute lane length (in bits)
        w=(r+c)//25

        # Initialisation of state
        S=[[0,0,0,0,0],
           [0,0,0,0,0],
           [0,0,0,0,0],
           [0,0,0,0,0],
           [0,0,0,0,0]]

        #Padding of messages
        P = self.pad10star1(M, r)

        if verbose:
            print("String ready to be absorbed: %s (will be completed by %d x '00')" % (P, c//8))

        [COLOR="Red"]#Absorbing phase[/COLOR]
        for i in range((len(P)*8//2)//r):
            Pi=self.convertStrToTable(P[i*(2*r//8):(i+1)*(2*r//8)]+'00'*(c//8))

            for y in range(5):
              for x in range(5):
                  S[x][y] = S[x][y]^Pi[x][y]
            S = self.KeccakF(S, verbose)

        if verbose:
            print("Value after absorption : %s" % (self.convertTableToStr(S)))

        #Squeezing phase
        Z = ''
        outputLength = n
        while outputLength>0:
            string=self.convertTableToStr(S)
            Z = Z + string[:r*2//8]
            outputLength -= r
            if outputLength>0:
                S = self.KeccakF(S, verbose)

            # NB: done by block of length r, could have to be cut if outputLength
            #     is not a multiple of r

        if verbose:
            print("Value after squeezing : %s" % (self.convertTableToStr(S)))

        return Z[:2*n//8]

EDIT: das rote kann man leider nicht sehen. Ist sehr weit unten (beide Methoden), da wo steht Adsorbing phase
 
Zuletzt bearbeitet:

andreas2505

Bekanntes Mitglied
Also das Problem mit der Länge habe ich gelöst. n muss der Wert in bits sein, also bei unserem Fall n=832 (104*8).

Allerdings stimmt die 7. und 8. Stelle des Strings noch nicht. Da kommt bei unserem Programm eine 1C, stehen muss da aber eine 39. Also stimmt irgendwas mit den Operationen nicht die da ausgführt werden.

EDIT:

Oder es hat noch was mit der Zeile zu tun:

Code:
if verbose:
            print("String ready to be absorbed: %s (will be completed by %d x '00')" % (P, c//8))

diese steht direkt nach dem Aufruf der Methode pad10star1.
d wäre für unseren Fall 48 bits bzw. 6 bytes!
 
Zuletzt bearbeitet:

Ariol

Top Contributor
Woher das m kommt kann ich leider immer noch nicht sehen; Es wird schon so an die Keccak-Funktion übergeben.
Wenn man 29 als m verwendet bekommt man wohl die richtige Ausgabe.

Der Algorithmus scheint also zu funktionieren, nur die Werte die reinkommen sind unklar.


Java:
import java.io.IOException;

public class Keccak
{
	private int b, w, l, nr;

	/*
	 * Class implementing the Keccak sponge function
	 */
	Keccak(int b/* =1600 */)
	{

		/*
		 * Constructor: b: parameter b, must be 25, 50, 100, 200, 400, 800 or
		 * 1600 (default value)
		 */
		this.setB(b);
	}

	void setB(int b)
	{
		/*
		 * Set the value of the parameter b (and thus w,l and nr)
		 * 
		 * b: parameter b, must be choosen among [25, 50, 100, 200, 400, 800,
		 * 1600]
		 */

		if (b != 25 && b != 50 && b != 100 && b != 200 && b != 400 && b != 800 && b != 1600)
		{
			throw new RuntimeException("b value not supported - use 25, 50, 100, 200, 400, 800 or 1600");
		}
		// Update all the parameters based on the used value of b
		this.b = b;
		this.w = b / 25;
		this.l = (int) (Math.log(this.w) / Math.log(2));
		this.nr = 12 + 2 * this.l;
	}

	// Constants

	// // Round constants
	long[] RC = new long[] { 0x0000000000000001 };// ,
	// 0x0000000000008082,
	// 0x800000000000808A,
	// 0x8000000080008000,
	// 0x000000000000808B,
	// 0x0000000080000001,
	// 0x8000000080008081,
	// 0x8000000000008009,
	// 0x000000000000008A,
	// 0x0000000000000088,
	// 0x0000000080008009,
	// 0x000000008000000A,
	// 0x000000008000808B,
	// 0x800000000000008B,
	// 0x8000000000008089,
	// 0x8000000000008003,
	// 0x8000000000008002,
	// 0x8000000000000080,
	// 0x000000000000800A,
	// 0x800000008000000A,
	// 0x8000000080008081,
	// 0x8000000000008080,
	// 0x0000000080000001,
	// 0x8000000080008008};

	// // Rotation offsets
	long[][] r = new long[][] { { 0, 36, 3, 41, 18 }, { 1, 44, 10, 45, 2 }, { 62, 6, 43, 15, 61 }, { 28, 55, 25, 21, 56 }, { 27, 20, 39, 8, 14 } };

	// // Generic utility functions

	long rot(long x, long n)
	{
		/*
		 * Bitwise rotation (to the left) of n bits considering the \ string of
		 * bits is w bits long
		 */
		n = n % this.w;
		return ((x >> (this.w - n)) + (x << n)) % (1 << this.w);
	}

	int fromHexStringToLane(String string)
	{
		/* Convert a string of bytes written in hexadecimal to a lane value */

		// Check that the string has an even number of characters i.e. whole
		// number of bytes
		if (string.length() % 2 != 0)
		{
			throw new RuntimeException("The provided string does not end with a full byte");
		}

		// Perform the modification
		String temp="";
		int nrBytes = string.length() / 2;
		for (int i = 0; i < nrBytes; i++)
		{
			int offset = (nrBytes - i - 1) * 2;
			temp += string.substring(offset, offset + 2);
		}
		return Integer.parseInt(temp, 16);
	}

	String fromLaneToHexString(long table)
	{
		/* Convert a lane value to a string of bytes written in hexadecimal */

		String laneHexBE = String.format(String.format("%%0%dX", (this.w / 4)), table);
		// Perform the modification
		String temp="";
		int nrBytes = laneHexBE.length() / 2;
		for (int i = 0; i < nrBytes; i++)
		{
			int offset = (nrBytes - i - 1) * 2;
			temp += laneHexBE.substring(offset, offset + 2);
		}
		return temp.toUpperCase();
	}

	void printState(long[][] state, String info)
	{
		/*
		 * Print on screen the state of the sponge function preceded by string
		 * info
		 * 
		 * state: state of the sponge function info: a string of characters used
		 * as identifier
		 */

		System.out.println("Current value of state: " + info);
		for (int y = 0; y < 5; y++)
		{
			StringBuilder line=new StringBuilder("\t");
			for (int x = 0; x < 5; x++)
			{
				line.append(String.format("%02",state[x][y]));
			}
			System.out.println(line.toString());
		}
	}

	// //// Conversion functions String <-> Table (and vice-versa)

	long[][] convertStrToTable(String string)
	{
		/*
		 * Convert a string of bytes to its 5×5 matrix representation
		 * 
		 * string: string of bytes of hex-coded bytes (e.g. '9A2C...");
		 */

		// Check that input paramaters
		if (this.w % 8 != 0)
		{
			throw new RuntimeException("w is not a multiple of 8");
		}
		if (string.length() != 2 * (this.b) / 8)
		{
			throw new RuntimeException("string can't be divided in 25 blocks of w bits i.e. string must have exactly b bits");
		}
		// Convert
		long[][] output = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				int offset = 2 * ((5 * y + x) * this.w) / 8;
				output[x][y] = this.fromHexStringToLane(string.substring(offset, offset + (2 * this.w / 8)));
			}
		}
		return output;
	}

	String convertTableToStr(long[][] table){
	        /*Convert a 5×5 matrix representation to its string representation*/

	        //Check input format
	    	if(this.w%8!= 0){
	            throw new RuntimeException("w is not a multiple of 8");
	            }
	        if (table.length!=5){
	            throw new RuntimeException("table must be 5×5");}
	        for (int i = 0; i < table.length; i++)
		        if (table[i].length!=5){
		            throw new RuntimeException("table must be 5×5");
		        }

	        //Convert
	        String output="";
            for(int y = 0; y < 5; y++)
            {
            	for(int x = 0; x < 5; x++)
            	{
	                output+=this.fromLaneToHexString(table[x][y]);
	            }
	        }
	        return output.toUpperCase();
	    }

	long[][] Round(long[][] A, long m)
	{
		/*
		 * Perform one round of computation as defined in the Keccak-f
		 * permutation
		 * 
		 * A: current state (5×5 matrix) RCfixed: value of round constant to use
		 * (integer)
		 */

		// Initialisation of temporary variables
		long[][] B = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
		long[] C = { 0, 0, 0, 0, 0 };
		long[] D = { 0, 0, 0, 0, 0 };

		// Theta step
		for (int x = 0; x < 5; x++)
		{
			C[x] = A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3] ^ A[x][4];
		}
		for (int x = 0; x < 5; x++)
		{
			D[x] = C[(x - 1) % 5] ^ this.rot(C[(x + 1) % 5], 1);
		}
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				A[x][y] = A[x][y] ^ D[x];
			}
		}

		// Rho and Pi steps
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				B[y][(2 * x + 3 * y) % 5] = this.rot(A[x][y], this.r[x][y]);
			}
		}

		// Chi step
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				A[x][y] = B[x][y] ^ ((~B[(x + 1) % 5][y]) & B[(x + 2) % 5][y]);
			}
		}

		// Iota step
		A[0][0] = A[0][0] ^ m;

		return A;
	}

	long[][] KeccakF(long[][] A, boolean verbose/* =False */)
	{
		/*
		 * Perform Keccak-f function on the state A
		 * 
		 * A: 5×5 matrix containing the state verbose: a boolean flag activating
		 * the printing of intermediate computations
		 */

		if (verbose)
		{
			this.printState(A, "Before first round");
		}

		for (int i = 0; i < this.nr; i++)
		{
			// NB: result is truncated to lane size
			A = this.Round(A, this.RC[i] % (1 << this.w));

			if (verbose)
			{
				this.printState(A, String.format("Satus end of round #%d/%d", i + 1, this.nr));
			}
		}
		return A;
	}

	public String pad10star1(int m, String M, int n)
	{
		// Padded die Nachricht M, so dass eine vielfache Länge von r erreicht
		// wird

		// M: message pair (length in bits, string of hex characters
		// ('9AFC...");
		// n: length in bits (must be a multiple of 8)
		// Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns
		// 'BA594E0FB9EBBD93'
		int my_string_length = m;
		String my_string = M;

		if (n % 8 != 0)
		{
			throw new RuntimeException("n must be a multiple of 8");
		}

		// Check the length of the provided string
		if (my_string.length() % 2 != 0)
		{
			// Pad with one '0' to reach correct length (don't know test vectors
			// coding)
			my_string += '0';

		}

		if (my_string_length > my_string.length() / 2 * 8)
		{
			throw new RuntimeException("the string is too short to contain the number of bits announced");
		}

		int nr_bytes_filled = my_string_length / 8;
		int nbr_bits_filled = my_string_length % 8;
		int l = my_string_length % n;

		int my_byte;

		if ((n - 8) <= l && l <= (n - 2))
		{
			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2 + 2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled)) + (1 << 7);
			String hex = String.format("%02X", my_byte);
			my_string = my_string.substring(0, nr_bytes_filled * 2) + hex;
		} else
		{

			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2 + 2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled));
			String hex = String.format("%02X", my_byte);
			my_string = my_string.substring(0, nr_bytes_filled * 2) + hex;
			while ((8 * my_string.length() / 2) % n < (n - 8))
			{
				my_string += "00";
			}
			my_string += "80";
		}
		return my_string;
	}

	public String Keccak(int m, String M, int r/* =1024 */, int c/* =576 */, int n/*
																				 * =
																				 * 1024
																				 */, boolean verbose/*
																									 * =
																									 * False
																									 */)
	{
		/*
		 * Compute the Keccak[r,c,d] sponge function on message M M: message
		 * pair (length in bits, string of hex characters ('9AFC..."); r:
		 * bitrate in bits (defautl: 1024) c: capacity in bits (default: 576) n:
		 * length of output in bits (default: 1024), verbose: print the details
		 * of computations(default:False)
		 */

		// Check the inputs
		if (r < 0 || r % 8 != 0)
		{
			throw new RuntimeException("r must be a multiple of 8 in this implementation");
		}
		if (n % 8 != 0)
		{
			throw new RuntimeException("outputLength must be a multiple of 8");
		}
		this.setB(r + c);

		if (verbose)
		{
			System.out.println(String.format("Create a Keccak function with (r=%d, c=%d (i.e. w=%d))", r, c, (r + c) / 25));
		}

		// Compute lane length (in bits)
		w = (r + c) / 25;

		// Initialisation of state
		long[][] S = new long[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };

		// Padding of messages
		String P = this.pad10star1(m, M, r);

		if (verbose)
		{
			System.out.println(String.format("String ready to be absorbed: %s (will be completed by %d x '00')", P, c / 8));
		}
		// Absorbing phase
		for (int i = 0; i < ((P.length() * 8 / 2) / r); i++)
		{
			long[][] Pi = this.convertStrToTable(String.format("%s%0" + c / 4 + "d", P.substring(i * (2 * r / 8), (i + 1) * (2 * r / 8)), 0));

			for (int y = 0; y < 5; y++)
			{
				for (int x = 0; x < 5; x++)
				{
					S[x][y] = S[x][y] ^ Pi[x][y];
				}
			}
			S = this.KeccakF(S, verbose);
		}

		if (verbose)
		{
			System.out.println("Value after absorption : " + (this.convertTableToStr(S)));
		}
		// Squeezing phase
		String Z = "";
		int outputLength = n;
		while (outputLength > 0)
		{
			String string = this.convertTableToStr(S);
			Z = Z + string.substring(0, r * 2 / 8);
			outputLength -= r;
			if (outputLength > 0)
			{
				S = this.KeccakF(S, verbose);
			}
		}
		// NB: done by block of length r, could have to be cut if outputLength
		// is not a multiple of r

		if (verbose)
		{
			System.out.println("Value after squeezing : %s " + (this.convertTableToStr(S)));
		}

		return Z.substring(0, 2 * n / 8);
	}

	public static void main(String[] args)
	{
		Keccak k = new Keccak(1600);
		System.out.println(k.pad10star1(60, "BA594E0FB9EBBD30", 8));
		System.out.println(k.pad10star1(29, "53587BC8", 104 * 8));

	}

}

Kannst ja mal ein bisschen mit rumspielen.
Vieles lässt sich sicher noch verbessern :wink:
 

andreas2505

Bekanntes Mitglied
ich weiß jetzt woher das m kommt. Das ist die Länge von der Eingabe M, aber in bits, also genau aufgeschlüsselt.

Gibts da ne Methode, wie man die Länge in bits noch ermitteln kann, so dass es dann den Wert automatisch übergibt, bzw. berechnet?
 

Ariol

Top Contributor
Java:
import java.io.IOException;

public class Keccak
{
	private int b, w, l, nr;

	/*
	 * Class implementing the Keccak sponge function
	 */
	Keccak(int b/* =1600 */)
	{

		/*
		 * Constructor: b: parameter b, must be 25, 50, 100, 200, 400, 800 or
		 * 1600 (default value)
		 */
		this.setB(b);
	}

	void setB(int b)
	{
		/*
		 * Set the value of the parameter b (and thus w,l and nr)
		 * 
		 * b: parameter b, must be choosen among [25, 50, 100, 200, 400, 800,
		 * 1600]
		 */

		if (b != 25 && b != 50 && b != 100 && b != 200 && b != 400 && b != 800 && b != 1600)
		{
			throw new RuntimeException("b value not supported - use 25, 50, 100, 200, 400, 800 or 1600");
		}
		// Update all the parameters based on the used value of b
		this.b = b;
		this.w = b / 25;
		this.l = (int) (Math.log(this.w) / Math.log(2));
		this.nr = 12 + 2 * this.l;
	}

	// Constants

	// // Round constants
	long[] RC = new long[] { 0x0000000000000001 };// ,
	// 0x0000000000008082,
	// 0x800000000000808A,
	// 0x8000000080008000,
	// 0x000000000000808B,
	// 0x0000000080000001,
	// 0x8000000080008081,
	// 0x8000000000008009,
	// 0x000000000000008A,
	// 0x0000000000000088,
	// 0x0000000080008009,
	// 0x000000008000000A,
	// 0x000000008000808B,
	// 0x800000000000008B,
	// 0x8000000000008089,
	// 0x8000000000008003,
	// 0x8000000000008002,
	// 0x8000000000000080,
	// 0x000000000000800A,
	// 0x800000008000000A,
	// 0x8000000080008081,
	// 0x8000000000008080,
	// 0x0000000080000001,
	// 0x8000000080008008};

	// // Rotation offsets
	long[][] r = new long[][] { { 0, 36, 3, 41, 18 }, { 1, 44, 10, 45, 2 }, { 62, 6, 43, 15, 61 }, { 28, 55, 25, 21, 56 }, { 27, 20, 39, 8, 14 } };

	// // Generic utility functions

	long rot(long x, long n)
	{
		/*
		 * Bitwise rotation (to the left) of n bits considering the \ string of
		 * bits is w bits long
		 */
		n = n % this.w;
		return ((x >> (this.w - n)) + (x << n)) % (1 << this.w);
	}

	int fromHexStringToLane(String string)
	{
		/* Convert a string of bytes written in hexadecimal to a lane value */

		// Check that the string has an even number of characters i.e. whole
		// number of bytes
		if (string.length() % 2 != 0)
		{
			throw new RuntimeException("The provided string does not end with a full byte");
		}

		// Perform the modification
		String temp="";
		int nrBytes = string.length() / 2;
		for (int i = 0; i < nrBytes; i++)
		{
			int offset = (nrBytes - i - 1) * 2;
			temp += string.substring(offset, offset + 2);
		}
		return Integer.parseInt(temp, 16);
	}

	String fromLaneToHexString(long table)
	{
		/* Convert a lane value to a string of bytes written in hexadecimal */

		String laneHexBE = String.format(String.format("%%0%dX", (this.w / 4)), table);
		// Perform the modification
		String temp="";
		int nrBytes = laneHexBE.length() / 2;
		for (int i = 0; i < nrBytes; i++)
		{
			int offset = (nrBytes - i - 1) * 2;
			temp += laneHexBE.substring(offset, offset + 2);
		}
		return temp.toUpperCase();
	}

	void printState(long[][] state, String info)
	{
		/*
		 * Print on screen the state of the sponge function preceded by string
		 * info
		 * 
		 * state: state of the sponge function info: a string of characters used
		 * as identifier
		 */

		System.out.println("Current value of state: " + info);
		for (int y = 0; y < 5; y++)
		{
			StringBuilder line=new StringBuilder("\t");
			for (int x = 0; x < 5; x++)
			{
				line.append(String.format("%02",state[x][y]));
			}
			System.out.println(line.toString());
		}
	}

	// //// Conversion functions String <-> Table (and vice-versa)

	long[][] convertStrToTable(String string)
	{
		/*
		 * Convert a string of bytes to its 5×5 matrix representation
		 * 
		 * string: string of bytes of hex-coded bytes (e.g. '9A2C...");
		 */

		// Check that input paramaters
		if (this.w % 8 != 0)
		{
			throw new RuntimeException("w is not a multiple of 8");
		}
		if (string.length() != 2 * (this.b) / 8)
		{
			throw new RuntimeException("string can't be divided in 25 blocks of w bits i.e. string must have exactly b bits");
		}
		// Convert
		long[][] output = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				int offset = 2 * ((5 * y + x) * this.w) / 8;
				output[x][y] = this.fromHexStringToLane(string.substring(offset, offset + (2 * this.w / 8)));
			}
		}
		return output;
	}

	String convertTableToStr(long[][] table){
	        /*Convert a 5×5 matrix representation to its string representation*/

	        //Check input format
	    	if(this.w%8!= 0){
	            throw new RuntimeException("w is not a multiple of 8");
	            }
	        if (table.length!=5){
	            throw new RuntimeException("table must be 5×5");}
	        for (int i = 0; i < table.length; i++)
		        if (table[i].length!=5){
		            throw new RuntimeException("table must be 5×5");
		        }

	        //Convert
	        String output="";
            for(int y = 0; y < 5; y++)
            {
            	for(int x = 0; x < 5; x++)
            	{
	                output+=this.fromLaneToHexString(table[x][y]);
	            }
	        }
	        return output.toUpperCase();
	    }

	long[][] Round(long[][] A, long m)
	{
		/*
		 * Perform one round of computation as defined in the Keccak-f
		 * permutation
		 * 
		 * A: current state (5×5 matrix) RCfixed: value of round constant to use
		 * (integer)
		 */

		// Initialisation of temporary variables
		long[][] B = { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
		long[] C = { 0, 0, 0, 0, 0 };
		long[] D = { 0, 0, 0, 0, 0 };

		// Theta step
		for (int x = 0; x < 5; x++)
		{
			C[x] = A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3] ^ A[x][4];
		}
		for (int x = 0; x < 5; x++)
		{
			D[x] = C[(x - 1) % 5] ^ this.rot(C[(x + 1) % 5], 1);
		}
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				A[x][y] = A[x][y] ^ D[x];
			}
		}

		// Rho and Pi steps
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				B[y][(2 * x + 3 * y) % 5] = this.rot(A[x][y], this.r[x][y]);
			}
		}

		// Chi step
		for (int x = 0; x < 5; x++)
		{
			for (int y = 0; y < 5; y++)
			{
				A[x][y] = B[x][y] ^ ((~B[(x + 1) % 5][y]) & B[(x + 2) % 5][y]);
			}
		}

		// Iota step
		A[0][0] = A[0][0] ^ m;

		return A;
	}

	long[][] KeccakF(long[][] A, boolean verbose/* =False */)
	{
		/*
		 * Perform Keccak-f function on the state A
		 * 
		 * A: 5×5 matrix containing the state verbose: a boolean flag activating
		 * the printing of intermediate computations
		 */

		if (verbose)
		{
			this.printState(A, "Before first round");
		}

		for (int i = 0; i < this.nr; i++)
		{
			// NB: result is truncated to lane size
			A = this.Round(A, this.RC[i] % (1 << this.w));

			if (verbose)
			{
				this.printState(A, String.format("Satus end of round #%d/%d", i + 1, this.nr));
			}
		}
		return A;
	}

	public String pad10star1(String M, int n)
	{
		// Padded die Nachricht M, so dass eine vielfache Länge von r erreicht
		// wird

		// M: message pair (length in bits, string of hex characters
		// ('9AFC...");
		// n: length in bits (must be a multiple of 8)
		// Example: pad10star1([60, 'BA594E0FB9EBBD30'],8) returns
		// 'BA594E0FB9EBBD93'
		int my_string_length = M.length()*4;
		int pos=M.length()-1;
		for(; pos > 0; pos--)
		{
			if(M.charAt(pos)!='0')
				break;
			my_string_length-=4;
		}
		String hexValue = ""+M.charAt(pos);
		int value = Integer.parseInt(hexValue, 16);
		String binValue = Integer.toString(value, 2);
		my_string_length-=(binValue.length()-binValue.lastIndexOf('1')-1);
		String my_string = M;

		if (n % 8 != 0)
		{
			throw new RuntimeException("n must be a multiple of 8");
		}

		// Check the length of the provided string
		if (my_string.length() % 2 != 0)
		{
			// Pad with one '0' to reach correct length (don't know test vectors
			// coding)
			my_string += '0';

		}

		if (my_string_length > my_string.length() / 2 * 8)
		{
			throw new RuntimeException("the string is too short to contain the number of bits announced");
		}

		int nr_bytes_filled = my_string_length / 8;
		int nbr_bits_filled = my_string_length % 8;
		int l = my_string_length % n;

		int my_byte;

		if ((n - 8) <= l && l <= (n - 2))
		{
			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2 + 2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled)) + (1 << 7);
			String hex = String.format("%02X", my_byte);
			my_string = my_string.substring(0, nr_bytes_filled * 2) + hex;
		} else
		{

			if (nbr_bits_filled == 0)
			{
				my_byte = 0;
			} else
			{
				my_byte = Integer.parseInt(my_string.substring(nr_bytes_filled * 2, nr_bytes_filled * 2 + 2), 16);
			}
			my_byte = (my_byte >> (8 - nbr_bits_filled));
			my_byte = my_byte + (1 << (nbr_bits_filled));
			String hex = String.format("%02X", my_byte);
			my_string = my_string.substring(0, nr_bytes_filled * 2) + hex;
			while ((8 * my_string.length() / 2) % n < (n - 8))
			{
				my_string += "00";
			}
			my_string += "80";
		}
		return my_string;
	}

	public String Keccak(int m, String M, int r/* =1024 */, int c/* =576 */, int n/*
																				 * =
																				 * 1024
																				 */, boolean verbose/*
																									 * =
																									 * False
																									 */)
	{
		/*
		 * Compute the Keccak[r,c,d] sponge function on message M M: message
		 * pair (length in bits, string of hex characters ('9AFC..."); r:
		 * bitrate in bits (defautl: 1024) c: capacity in bits (default: 576) n:
		 * length of output in bits (default: 1024), verbose: print the details
		 * of computations(default:False)
		 */

		// Check the inputs
		if (r < 0 || r % 8 != 0)
		{
			throw new RuntimeException("r must be a multiple of 8 in this implementation");
		}
		if (n % 8 != 0)
		{
			throw new RuntimeException("outputLength must be a multiple of 8");
		}
		this.setB(r + c);

		if (verbose)
		{
			System.out.println(String.format("Create a Keccak function with (r=%d, c=%d (i.e. w=%d))", r, c, (r + c) / 25));
		}

		// Compute lane length (in bits)
		w = (r + c) / 25;

		// Initialisation of state
		long[][] S = new long[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };

		// Padding of messages
		String P = this.pad10star1(M, r);

		if (verbose)
		{
			System.out.println(String.format("String ready to be absorbed: %s (will be completed by %d x '00')", P, c / 8));
		}
		// Absorbing phase
		for (int i = 0; i < ((P.length() * 8 / 2) / r); i++)
		{
			long[][] Pi = this.convertStrToTable(String.format("%s%0" + c / 4 + "d", P.substring(i * (2 * r / 8), (i + 1) * (2 * r / 8)), 0));

			for (int y = 0; y < 5; y++)
			{
				for (int x = 0; x < 5; x++)
				{
					S[x][y] = S[x][y] ^ Pi[x][y];
				}
			}
			S = this.KeccakF(S, verbose);
		}

		if (verbose)
		{
			System.out.println("Value after absorption : " + (this.convertTableToStr(S)));
		}
		// Squeezing phase
		String Z = "";
		int outputLength = n;
		while (outputLength > 0)
		{
			String string = this.convertTableToStr(S);
			Z = Z + string.substring(0, r * 2 / 8);
			outputLength -= r;
			if (outputLength > 0)
			{
				S = this.KeccakF(S, verbose);
			}
		}
		// NB: done by block of length r, could have to be cut if outputLength
		// is not a multiple of r

		if (verbose)
		{
			System.out.println("Value after squeezing : %s " + (this.convertTableToStr(S)));
		}

		return Z.substring(0, 2 * n / 8);
	}

	public static void main(String[] args)
	{
		Keccak k = new Keccak(1600);
		System.out.println(k.pad10star1("BA594E0FB9EBBD30", 8));
		System.out.println(k.pad10star1("53587BC8", 104 * 8));

	}

}

So, es gibt noch eine fehlende Stelle bei der initialisierung von RC. Da musst du noch nach sehen.
 

andreas2505

Bekanntes Mitglied
Also ich denke mal, dass dieser Teil die Länge berechnen soll:

Java:
int my_string_length = M.length()*4;
        int pos=M.length()-1;
        for(; pos > 0; pos--)
        {
            if(M.charAt(pos)!='0')
                break;
            my_string_length-=4;
        }
        String hexValue = ""+M.charAt(pos);
        int value = Integer.parseInt(hexValue, 16);
        String binValue = Integer.toString(value, 2);
        my_string_length-=(binValue.length()-binValue.lastIndexOf('1')-1);

Allerdings funktioniert das nur für manche Werte:

Gegenbeispiele:

"50" kommt statt 6 4 raus
"5030" kommt statt 13 12 raus
 

Ariol

Top Contributor
Ich weiß ja nicht wie dur rechnest, aber ich bekomme das hier raus:
Code:
0x50   = 1001000         = 4bit 
0x5030 = 100100000110000 =12bit

Wo ist das Problem?
 

andreas2505

Bekanntes Mitglied
Ich denke mir ja die Werte nicht aus!!!

Ich weiß ja dass es eigentlich das macht, aber in der Übersicht (die ihr euch ja auch alle mal angucken könnt) sind noch mehr solche Wertepaare wo es nicht hinhaut!!!

Bsp. 17 --> 4FF400
ist ja eigentlich 010011111111010000000000
damit müsste Länge 14 rauskommen


oder 19 --> 424D00
010000100100110100000000
müsste ja eigentlich 16 rauskommen.

Die haben sich ja nicht bei jedem Beispiel verschrieben!!!

Also muss da irgendein anderer "Trick" dahinter stecken, aber ich weiß ihn leider auch nicht.
 

Ariol

Top Contributor
Also, der Trick dahinter ist wohl dieser:

Code:
10110000 -> 10110000 -> B0 (m=8)
1011000  -> 10110000 -> B0 (m=7)
1011     -> 10110000 -> B0 (m=4)
11       -> 11000000 -> C0 (m=2)
110      -> 11000000 -> C0 (m=3)

Du kannst diesen Wert also nicht aus der Hexadezimalzahl errechnen.

Vielleicht solltest du statt ein Python-Programm zu übersetzen, dir den Algorithmus aneignen und selbst eine passende und funktionierende Version schreiben.
 

andreas2505

Bekanntes Mitglied
Vielleicht solltest du statt ein Python-Programm zu übersetzen, dir den Algorithmus aneignen und selbst eine passende und funktionierende Version schreiben.

Ich habe den Algorithmus bereits selber implementiert gehabt, anhand der Paper usw., allerdings bin ich genau dann immer wieder auf das Problem gestoßen, dass es nicht funktioniert aus dem Eingabestring den Wert zu gewinnen, der dann im Schritt danach nötig ist, um die weiteren Schritte auszuführen.

Deshalb habe ich anhand derer Implementierung versucht das umzusetzen. Es funktioniert ja auch, bis auf dass ich halt nicht auf diese Länge komme.

Gut was du da erklärt hast ist ja logisch, aber irgendwie muss es doch möglich sein, das ganze in einen Zusammenhang zu bringen (also den String und die Länge).

Ich kann ja theoretisch auch einfach sagen, ich habe zwei Eingabeparameter, den String und die Länge, und schon ist mein Problem gelöst, dann funktioniert ja alles. Aber ich dachte halt, dass man nur anhand des Strings auch die Länge ermitteln kann und damit für den Benutzer die ganze Sache stark vereinfach kann....
 

Ariol

Top Contributor
Du gehst das Problem falsch an.

Das was du in Wirklichkeit in den Algorithmus steckst ist eine Bitfolge wie z.B.: 011100001101... und deren Länge wird verwendet.
Dass dann der Lesbarkeit halber Hexadezimalzahlen verwendet werden tut dabei nichts zur Sache.
Hättest du lieber sowas da stehen?
101110100101100101001110000011111011100111101011101111010011
Das ist nämlich die Eingabe für BA594E0FB9EBBD30
 

tricky00

Neues Mitglied
Hallo Leute,

ich habe ein kleines Problem und hoffe ihr könnt mir helfen.
Ich würde gerne ein Button erstellen der folgendes machen soll.
In meinem admin Bereich würde ich gerne zwei Button erstellen, einer soll die Farbe grün haben und der andere rot.
In meinem Userbereich möchte ich einen Button haben der gelb ist.
Es soll nun so sein, wenn ich im Admin bereich auf den grünen Button drücke soll der Button im userbereich im selben Augenblick sich in grün ändern und genau das gleiche mit dem roten. wie kann ich dass machen?

Danke
 

Ariol

Top Contributor
Hallo Leute,

ich habe ein kleines Problem und hoffe ihr könnt mir helfen.
Ich würde gerne ein Button erstellen der folgendes machen soll.
In meinem admin Bereich würde ich gerne zwei Button erstellen, einer soll die Farbe grün haben und der andere rot.
In meinem Userbereich möchte ich einen Button haben der gelb ist.
Es soll nun so sein, wenn ich im Admin bereich auf den grünen Button drücke soll der Button im userbereich im selben Augenblick sich in grün ändern und genau das gleiche mit dem roten. wie kann ich dass machen?

Danke

Hi tricky,

wie wär's wenn du einen neuen Thread mit deinem Thema anlegst, anstatt hier hin zu schreiben, wo es einfach nicht hingehört? :wink:
 

andreas2505

Bekanntes Mitglied
Das was du in Wirklichkeit in den Algorithmus steckst ist eine Bitfolge wie z.B.: 011100001101... und deren Länge wird verwendet.
Dass dann der Lesbarkeit halber Hexadezimalzahlen verwendet werden tut dabei nichts zur Sache.

Da hast du Recht. Aus der Sicht hab ich das wirklich noch nicht gesehen. Kann man das denn irgendwie umsetzen, dass man praktisch die Bitfolge eingeben würde, daraus dann die Länge ja relativ einfach ableiten kann und dann aber auch den String in Hexadezimal daraus kriegt.
 
B

bone2

Gast
die längenangabe gibt also nur an, die ersten wieviel stellen du von dem hex->bin ergebnis nehmen musst.

Bsp. 17 --> 4FF400
ist ja eigentlich 010011111111010000000000
gerechnet wird mit: 01001111111101000

hast du eigentlich keinen tutor/berater/was-weiß-ich den du bei so grundlegenden verständisschwierigkeiten der aufgabe befragen kannst?

was gemacht werden muss/gemacht wurde:
-bitfolge einlesen
-länge speichern
-mit 0 oder 1 auffüllen bis zum nächsten vollen 8 bit wert
-in hex umrechnen
-länge und hexwert übergeben

Bsp. 17 --> 4FF47F
=010011111111010001111111
wäre auch
01001111111101000
rückwärts gehts nicht, nuraus dem hexwert bekomsmt du nie wieder die richtige länge
 
Zuletzt bearbeitet von einem Moderator:
Ähnliche Java Themen
  Titel Forum Antworten Datum
B Objekte verschwinden beim Übersetzen Java Basics - Anfänger-Themen 5
F Linux Befehle zum Übersetzen Java Basics - Anfänger-Themen 1
V Übersetzen in Leet Java Basics - Anfänger-Themen 3
J Zahlen in Worte "Übersetzen" Java Basics - Anfänger-Themen 6
F Probleme beim Übersetzen Java Basics - Anfänger-Themen 7
B Java Programm soll mit Python kommunizeren Java Basics - Anfänger-Themen 1
A Python und Java gleichzeitig lernen? Java Basics - Anfänger-Themen 5
K Java Client > Python Server Java Basics - Anfänger-Themen 0
B Java oder Python Java Basics - Anfänger-Themen 43
T Umstieg von Python auf Java Java Basics - Anfänger-Themen 7
H Python -> Java: Umsteigerfragen Java Basics - Anfänger-Themen 2
J Probleme mit drucken aus Java Java Basics - Anfänger-Themen 3
Gokul Java chart library suggestion for web application? Java Basics - Anfänger-Themen 2
D wie kann ich gcc aus einer .java datei heraus aufrufen? Java Basics - Anfänger-Themen 2
S Text Formatierung in Java Java Basics - Anfänger-Themen 2
B Erste Schritte yaml parsen in Java Java Basics - Anfänger-Themen 19
C Methoden Umlaute in Java Java Basics - Anfänger-Themen 18
W Java-PRogramm liest als EXE-File Nicht USB, jedoch aus NetBeans Java Basics - Anfänger-Themen 45
W Methoden java map ersatz für c++map Java Basics - Anfänger-Themen 3
M Erste Schritte Java Primzahltester Java Basics - Anfänger-Themen 4
A csv Reader für Java? Java Basics - Anfänger-Themen 27
K Java - Enums Java Basics - Anfänger-Themen 30
tomzen Java Unterstützung für exel dateien installieren. Java Basics - Anfänger-Themen 2
Rookar java.lang.NoClassDefFoundError: org/json/JSONException Java Basics - Anfänger-Themen 2
Rookar Mit Button andere java öffnen Java Basics - Anfänger-Themen 4
F Java Object to Hashmap ? Java Basics - Anfänger-Themen 6
I Backend in Java und Ansicht von Dateien in statische HTML Seiten? Java Basics - Anfänger-Themen 15
R Input/Output Verwendung des Euro-Zeichens in Java Java Basics - Anfänger-Themen 7
I Push Nachrichten von JAVA EE App an Mobile App Java Basics - Anfänger-Themen 3
H .java Dateien in Eclipse einbinden und ausführen Java Basics - Anfänger-Themen 1
onlyxlia Schlüsselworte Was meint man mit "einen Typ" in Java erstellen? Java Basics - Anfänger-Themen 2
O Java Kara geschweifte Klammern Java Basics - Anfänger-Themen 2
G Mausrad logitech kann links und rechts klick wie in java abragen. Java Basics - Anfänger-Themen 15
XWing Java Klssenproblem Java Basics - Anfänger-Themen 4
R Umgebungsvariable java -cp gibt immer Java-Hilfe... Java Basics - Anfänger-Themen 3
farbenlos Csv Datei in Java einlesen Java Basics - Anfänger-Themen 18
F TableModelListener: java.lang.ArrayIndexOutOfBoundsException: 132 Java Basics - Anfänger-Themen 3
G Java 8 - Support-Ende Java Basics - Anfänger-Themen 7
T Java Weihnachtsbaum + Rahmen Java Basics - Anfänger-Themen 1
N Will mit Java anfangen Java Basics - Anfänger-Themen 13
Ü Java Array - Buchstaben als Zahlen ausgeben Java Basics - Anfänger-Themen 22
M Java Iterator Verständnisfrage Java Basics - Anfänger-Themen 6
M Java Mail Programm Java Basics - Anfänger-Themen 4
Sniper1000 Java 391 für Windows Java Basics - Anfänger-Themen 37
G Java long- in int-Variable umwandeln Java Basics - Anfänger-Themen 6
JaZuDemNo Java im Studium Java Basics - Anfänger-Themen 7
E Java Programm zur anzeige, ob Winter- oder Sommerzeit herrscht Java Basics - Anfänger-Themen 62
I QR code in Java selber generieren Java Basics - Anfänger-Themen 5
V Java-Ausnahmebehandlung: Behandlung geprüfter Ausnahmen Java Basics - Anfänger-Themen 1
krgewb Java Streams Java Basics - Anfänger-Themen 10
A Überwältigt von der komplexen Java Welt Java Basics - Anfänger-Themen 29
O Mehrfachvererbung auf Spezifikations- und Implementierungsebene in Java. Interfaces Java Basics - Anfänger-Themen 19
John_Sace Homogene Realisierung von Generics in Java ? Java Basics - Anfänger-Themen 19
P Meldung aus Java-Klasse in Thread an aufrufende Klasse Java Basics - Anfänger-Themen 1
R mit Java API arbeiten Java Basics - Anfänger-Themen 9
P JDK installieren Probleme bei der Java-Installation Java Basics - Anfänger-Themen 8
S Java: Wie sortiere ich eine ArrayList benutzerdefinierter Objekte nach einem bestimmten Attribut? Java Basics - Anfänger-Themen 2
Timo12345 JNLP File mit Java öffnen Java Basics - Anfänger-Themen 2
S Video Editierung mit Java.._ Java Basics - Anfänger-Themen 2
F Einstelungen in Java - CursorBlinkRate Java Basics - Anfänger-Themen 10
A PHP $_POST["name"] in Java Java Basics - Anfänger-Themen 3
vivansai21 Is there a oneliner to create a SortedSet filled with one or multiple elements in Java? Java Basics - Anfänger-Themen 9
Athro-Hiro Weißes Bild in Java erstellen Java Basics - Anfänger-Themen 3
Arjunreddy Can someone please tell me how to use a debugger in BlueJ(a Java environment) Java Basics - Anfänger-Themen 1
M Java assoziationen (UML) Java Basics - Anfänger-Themen 8
H Excel-Tabellen mit Java erstellen Java Basics - Anfänger-Themen 4
Simon16 Java ArrayListe von einer Klasse sortieren Java Basics - Anfänger-Themen 2
P Wie kann ich in meinem Java Programm etwas dauerhaft speichern? Java Basics - Anfänger-Themen 5
H Nutzt Eclipse alle CPU-Threads beim Ausführen von Java-Programmen? Java Basics - Anfänger-Themen 4
xXGrowGuruXx Java einstieg, leichte sache 0 verstanden Java Basics - Anfänger-Themen 7
A java.sql.SQLException: Data type mismatch. Java Basics - Anfänger-Themen 1
H Java-Programm zur Ausgabe von Zuständen Java Basics - Anfänger-Themen 80
N Java Spiel Figur auf dem Hintergrundbild bewegen. Java Basics - Anfänger-Themen 11
G Kann Java-Programm nicht als jar aufrufen, auch als EXE nicht Java Basics - Anfänger-Themen 19
N Java Taschenrechner hat Jemand vlt einen Tipp dafür wie ich jetzt die buttons verbinden kann und das Ergebnis auf dem textfield anzeigen lassen kann Java Basics - Anfänger-Themen 13
A Lerngruppe Java Java Basics - Anfänger-Themen 2
G Help me in the Java Program Java Basics - Anfänger-Themen 2
L Java- Vererbung Java Basics - Anfänger-Themen 4
LimDul Suche Java Stream Tutorial Java Basics - Anfänger-Themen 2
_so_far_away_ Ich möchte Java lernen Java Basics - Anfänger-Themen 11
benny1993 Java Programm erstellen für ein Fußball-Turnier Java Basics - Anfänger-Themen 3
M Datentypen While-Schleife eine Java Methode erstellen Java Basics - Anfänger-Themen 3
V Bild per Java Script austauschen Java Basics - Anfänger-Themen 7
MoxMorris this Keyword in Java Java Basics - Anfänger-Themen 14
D Wie kann man in Java nach Arrays auf Duplikate prüfen Java Basics - Anfänger-Themen 12
wolei JAVA Zeitdifferenz feststellen. Java Basics - Anfänger-Themen 4
DiyarcanZeren Rekursion in Java Java Basics - Anfänger-Themen 5
wolei Java generic interface in a generic class Java Basics - Anfänger-Themen 6
monsterherz Ablauf der Erstellung eines Java Programmes Java Basics - Anfänger-Themen 17
monsterherz Circle.java:5: error: <identifier> expected Java Basics - Anfänger-Themen 2
julian-fr Wie kann ich am besten Java lernen? Java Basics - Anfänger-Themen 17
A Java-Properties und -RessourceBundles Java Basics - Anfänger-Themen 5
lrnz22 Java-Basics-Aufgabe Java Basics - Anfänger-Themen 8
R Java kann nicht installiert werden Java Basics - Anfänger-Themen 8
marcelnedza Finde meinen Fehler in einer Methode nicht, Java Karol Java Basics - Anfänger-Themen 15
G In ein java Dokument Ton einbinden Java Basics - Anfänger-Themen 1
C was heisst es wenn java ']' erwartet ? Java Basics - Anfänger-Themen 2
KeinJavaFreak Erste Schritte Programm "Java(TM) Platform SE binary " nicht vorhanden Java Basics - Anfänger-Themen 1
KeinJavaFreak Erste Schritte Java "Executable Jar File" nicht vorhanden Java Basics - Anfänger-Themen 1
melisax Java 2D-Array Tabelle Java Basics - Anfänger-Themen 4

Ähnliche Java Themen

Neue Themen


Oben