Add shiftRows
This commit is contained in:
		
							parent
							
								
									241df8d4a5
								
							
						
					
					
						commit
						c86f60135a
					
				@ -60,6 +60,13 @@ class Aes {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun shiftRows() {
 | 
			
		||||
        stateMatrix[0] = arrayOf(stateMatrix[0][0], stateMatrix[0][1], stateMatrix[0][2], stateMatrix[0][3])
 | 
			
		||||
        stateMatrix[1] = arrayOf(stateMatrix[1][1], stateMatrix[1][2], stateMatrix[1][3], stateMatrix[1][0])
 | 
			
		||||
        stateMatrix[2] = arrayOf(stateMatrix[2][2], stateMatrix[2][3], stateMatrix[2][0], stateMatrix[2][1])
 | 
			
		||||
        stateMatrix[3] = arrayOf(stateMatrix[3][3], stateMatrix[3][0], stateMatrix[3][1], stateMatrix[3][2])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun expandKey(key: AesKey) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -27,4 +27,29 @@ class AesTest {
 | 
			
		||||
            aes.stateMatrix[0][0] == 0xEDU.toUByte()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    fun testShiftRows() {
 | 
			
		||||
        val fakeState = arrayOf(
 | 
			
		||||
                ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
 | 
			
		||||
                ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
 | 
			
		||||
                ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
 | 
			
		||||
                ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray()
 | 
			
		||||
        )
 | 
			
		||||
        val expectedState = arrayOf(
 | 
			
		||||
                ubyteArrayOf(0U, 1U, 2U, 3U).toTypedArray(),
 | 
			
		||||
                ubyteArrayOf(1U, 2U, 3U, 0U).toTypedArray(),
 | 
			
		||||
                ubyteArrayOf(2U, 3U, 0U, 1U).toTypedArray(),
 | 
			
		||||
                ubyteArrayOf(3U, 0U, 1U, 2U).toTypedArray()
 | 
			
		||||
        )
 | 
			
		||||
        val aes = Aes()
 | 
			
		||||
        fakeState.copyInto(aes.stateMatrix)
 | 
			
		||||
        aes.shiftRows()
 | 
			
		||||
        aes.stateMatrix.forEach{
 | 
			
		||||
            println(it.joinToString { it.toString(16) })
 | 
			
		||||
        }
 | 
			
		||||
        assertTrue {
 | 
			
		||||
            aes.stateMatrix.contentDeepEquals(expectedState)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user