Go Back   Sat Universe > Encryptions > Encryptions chat

Note: Visitors from certain countries might see in-text advertising(underlind words in posts) or pop-under ads.
It is only shown to unregistered visitors or members that haven't made any posts. So you can easily get rid of it.

World-Of-Satellite

Encryption Learning - Code Exercise Area

Encryptions chat

Reply
  #1  
Old 13-01-2022, 23:33  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default Encryption Learning - Code Exercise Area

To moderators I need your help here. Please moved this thread to any area you may think it better. I think should stay here in the encryption area. That is why I choose tittle Encryptiom Learning - Code Exercise Area. But to be honest we will be disusing C code exercises that will be use to practice encryption. You decide.

This is the area for hands on exercises in C for the thread Encryption Learning at https://www.sat-universe.com/showthread.php?t=318003

But feel free to ask any help you may have. This is just a scrap book.

I strongly suggest you use Linux. I had a in the PC Chat area two useful threads:

Linux OS suggestion
https://www.sat-universe.com/showthread.php?t=319133

CodeBlocks IDE Installation on Windows 11 & Linux
MinGW GCC Compiler
And some how to and tutorials
https://www.sat-universe.com/showthread.php?t=318084

The Idea is to provide C code in a Project Form. I will be using FREE GNU Compiler (MINGW) and Codeblock as the IDE. So feel free to start installing Codeblock in your Windows or Linux OS.

In a few hours I will be posting some exercise code.

Last edited by cayoenrique; 13-01-2022 at 23:40..
Reply With Quote
The Following 3 Users Say Thank You to cayoenrique For This Useful Post:
barney115 (14-01-2022), kakero (14-01-2022), m.megris (14-01-2022)
  #2  
Old 14-01-2022, 09:59  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

Here we go 1rst Codeblock project.

It is just the CSA Key Schedule as it was implemented on 2004.

Use this to test your Codeblock IDE. See attachment.
Attached Files
File Type: tar csa_core_017_key_shedule.tar.xz.tar (7.4 KB, 10 views)
Reply With Quote
The Following 2 Users Say Thank You to cayoenrique For This Useful Post:
kakero (14-01-2022), Me2019H (14-01-2022)
  #3  
Old 14-01-2022, 22:10  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
Me2019H Me2019H is offline
Senior Member
 
Join Date: Dec 2019
Posts: 43
Thanks: 66
Thanked 9 Times in 8 Posts
Country: Country Flag
Default

Hello,
from where you get this permutation table to get the keys
0x12,0x24,0x09,0x07,0x2A,0x31,0x1D,0x15,0x1C,0x36,0x3E,0x32, 0x13,0x21,0x3B,0x40,
0x18,0x14,0x25,0x27,0x02,0x35,0x1B,0x01,0x22,0x04,0x0D,0x0E, 0x39,0x28,0x1A,0x29,
0x33,0x23,0x34,0x0C,0x16,0x30,0x1E,0x3A,0x2D,0x1F,0x08,0x19, 0x17,0x2F,0x3D,0x11,
0x3C,0x05,0x38,0x2B,0x0B,0x06,0x0A,0x2C,0x20,0x3F,0x2E,0x0F, 0x03,0x26,0x10,0x37,

first key in decimal
18,44,09,07,42,49,29,21


i'm trying to understant the code

Last edited by Me2019H; 14-01-2022 at 22:20..
Reply With Quote
  #4  
Old 15-01-2022, 04:08  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

@All others. Do not read further. Only you need to know 8 byte original keys enter. At the end it output kk witch have 56 new different bytes.

@Me2019H
I do not know you. But I like your perseverance. We only see a guy saying: "I want to learn." Who knows, may be behind that, there is a real smart guy or a genius.

Now never let nobody intimidate you. Ask all you want. Here the only smart guy is you, the one asking. This hex stuff is important. If you do not pass this you will be destine to fail. I am not making fun of you. I am trying to convince you.

1) This is the most disturbing of your comment: first key in decimal
Why are you wasting time in translation?
I will give you an example. People ask why they can not learn a second language?
Those that fail is because they try to translate every word. They translate, to think on their native language. Wrong. In the other hand, a guy that manage 2 language do in fact think in another language. When sleeping he even dream on different languages.

Here is the same. CPU alphabet is 0 or 1. On or Off, Clear or Set. Now If we humans try to speak or write binary, we run out of ink. Numbers are to longggggggg. So we use Hex instead. In general 2 Hex is like one of our letters. So Hex is the choosing number system in the digital word.

Now if you intent to program or even do Cryptography you can not translate every word you see. You need to think in Hex. There are exceptions, Lest say a Loop. You know CSA block loops are 56. So to know who long it will take you then print in Decimal. So that you can quickly know where you at. Lets say 28. aHhaaa! this means I am at the middle of the loop.
Now the values/calculations in the loop, you leave them in HEX.

Lets make a final joke. I did say:
Here is the same.

Just Imagine I am a translation type of guy... So I am learning to read.

"H..e..r..e"
OH boy learning to read is difficult... I know this one this mean where I am. Ok lets continue
"i..s"
I do not know this one, may be has something to do with the theorist ISIS.!!!
"t..h..e"
Have no Idea. Why reading is so hard....
"s..a..m..e"
Ok ok, I know this one it means equal. SO I got 2 of 4, I know" where I am" and "equal". So I star looking around me trying to find something where I am that are equals!!! HEHEHEHE Yes Lost in Space because I am trying to translate.


So lets go back to objective. Key1 is NOT "18,44,09,07,42,49,29,21" The Key1 is 0x38, 0x5F, 0x62, 0xF9, 0x4F, 0xCA, 0xBC, 0xD5

2) from where you get this permutation table to get the keys
Please read my explanation on S-Box and why tables. See https://www.sat-universe.com/showpos...&postcount=141

I know what you want me to do is to show you how the kk are created from ck. And how the S-box is used in the process. We will do this for the 1rst experience. But we need to have faith. Or we will never relive in God.

Nest post a Class on C. next in a few minutes...
Reply With Quote
The Following User Says Thank You to cayoenrique For This Useful Post:
Me2019H (15-01-2022)
  #5  
Old 15-01-2022, 04:47  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

Code:
uint8_t key_perm[0x40] =
{
    0x12,0x24,0x09,0x07,0x2A,0x31,0x1D,0x15,0x1C,0x36,0x3E,0x32,0x13,0x21,0x3B,0x40,
    0x18,0x14,0x25,0x27,0x02,0x35,0x1B,0x01,0x22,0x04,0x0D,0x0E,0x39,0x28,0x1A,0x29,
    0x33,0x23,0x34,0x0C,0x16,0x30,0x1E,0x3A,0x2D,0x1F,0x08,0x19,0x17,0x2F,0x3D,0x11,
    0x3C,0x05,0x38,0x2B,0x0B,0x06,0x0A,0x2C,0x20,0x3F,0x2E,0x0F,0x03,0x26,0x10,0x37,
};
In C when you are about to use a Variable, you need to express what type of variable. In this case is uint8_t

uint8_t

u This mean unsigned it hold a number that had no signed. So no negatives numbers only positive. By doing this we can use all 8 bits to represent numbers. So 2^8 = 2*2*2*2*2*2*2*2 = 256. I goes from 0 to 255. Yes 0 is 1rst number. 255 is last. A signed number in the other hand loses 1 bit. That last bit is use to say if it is positive (0) or negative (1). A signed number then can only count from -127..0..127. See the different. Just know we use unsigned to simplify understanding. As we really mean 0 to 255.

int This mean Integer. Yes no floating point. The number can not be 1.5 or 240.7. Only integers so, 0-256.

8 This means we can use only 8 bit ( 0 to 7). Any bit large will be ignore. So if I try to say a = 255; This variable a will hold [11111111] = 255. I f I say a = 256; this has 1 extra bit. 256 has 8 bit or [100000000]. But it can hold ONLY 7. So we ignore the last and keep only 7. This means a = 256 result on an error or we keep only 7. So A=256 will hold only [00000000] or at the end [b]a[/] will be
0. Waooo from 256 I only keep 0. Amazing....

_t This you ignore. But as we become a Global society these means we need to conciser other languages and their extended alphabet. So it try to means it is a safe number to be used. Just ignore unimportant.

key_perm This is the name of our variable.

[0x40] Because you see a square brackets "[]" this mean is an Array. How big? 0x40 Ok 0x40 is a Hex number. You should not translate right? Well as I say from time to time you do. So what is 0x40 = 64. So the array can contain 64 variables. But because we start with 0 this mean we can have
key_perm[0]
key_perm[1]
key_perm[2]
***
key_perm[63]

with values
key_perm[0] = 0x12
key_perm[1] = 0x24
key_perm[2] = 0x09
***
key_perm[63] = 0x37

Now do not forget the importance or objective, This are Substitution tables. This them mean if I have
0x00 => 0x12
0x01 => 0x24
0x02 => 0x09
***
0x39(63) => 0x37

So Arrays are a way to say change Original Number to New Number
Array[Original Number] = New Number
Reply With Quote
The Following User Says Thank You to cayoenrique For This Useful Post:
Me2019H (15-01-2022)
  #6  
Old 15-01-2022, 05:11  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

In C we have subroutines. This are specialize sub programs and we have the One and ONLY One main.

When compile the compiler looks for main he knows this is the 1rst of all subroutine. Where all start. So we can not have more that one main or we all get screwed. Then where we start. Well to be fair we can have many subroutines but none can have same name.

Code:
int main(int argc, char *argv[])
{

    return 0;
}

int As require by C all need type declare. This read then is an Integer so no floating point.

main( ) Here we do not see square brackets instead are the parentheses . If see see this mean is a subroutine.

int argc, char *argv[] Ignore this complex form but this are called Arguments. Are values or variables we pass to the subroutine. This are the Inputs.

Then what is the Output or result? Remember it is Integer. So we point the result with the return statement or
return 0;

{ } This are use to group and point out from { to }

Finnaly
; In cw we are required to use semi columns ; after each command.
Reply With Quote
The Following User Says Thank You to cayoenrique For This Useful Post:
Me2019H (15-01-2022)
  #7  
Old 15-01-2022, 05:44  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

Ok Lets continue.

key_schedule(uint8_t *CK, uint8_t *kk)

Code:
void key_schedule(uint8_t *CK, uint8_t *kk)
{

    return;
}

void As require by C all need type declare. This read then is Void. This is just a special type. It mean is not define. You may ask why? well we intent NOT to return any value. So if we are not going to return a value, then why say it is Integer!!

key_schedule( ) Here we see key_schedule brackets, this mean is a subroutine.

Then what is the Output or result?
return;

Arguments: uint8_t *CK, uint8_t *kk
uint8_t This mean they are 8 bit unsigned

Please notice "*" in uint8_t *CK, uint8_t *kk
This mean that instead of passing a copy of the variables, instead we passing a Pointer to those variables. A pointer is a spacial variable that instead of holding a value it in fact hold the address of the variable in RAM. As result even when the variable should not be pass. It in fact point to the same variable from the program that calls this subroutine. So at the end result is that it in fact will affect the original variable.

Listen if you are newbie, what you need to only understand is that arguments are mean to pass not the same variables. Instead Copies are pass as Input. Reinforcing Input. But by using "*" then this Inputs in fact becomes an Input + and Output variable.

More simply, if we modify its value inside the subroutine, then the variable get change.
uint8_t *CK, Here we pass in the original 8 bytes
uint8_t *kk Here we return the modified 56 bytes
Reply With Quote
The Following User Says Thank You to cayoenrique For This Useful Post:
Me2019H (15-01-2022)
  #8  
Old 15-01-2022, 06:36  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

I will continue with 2004 implementation as 1 C tutorial in Basics.

But the point is Math is complex. And I have a feeling that if I try to explain. I will fail. The I recall colibri's cuda implementation. Boy this is a great Idea as master colibri did a wonderful simplification that will definitely help you understand whats going on.

Code:
#: mkdir -p $HOME/cryptodir/Labs/colibri
#: cd $HOME/cryptodir/Labs/colibri
#: wget http://colibri.bplaced.net/CSA-Rainbow-Table-Tool_V1.03.zip
#: unzip CSA-Rainbow-Table-Tool_V1.03.zip
#: unzip 'Source Code.zip'
#: cp 'CSA-Rainbow-Table-Tool - V1.03/CSA-Rainbow-Table-Tool/cuda/cuda.cu' cuda.c
#: cat cuda.c | grep KeySchedule07_Xor -m 1 -A 70 > KeySchedule07_Xor.txt
#: geany KeySchedule07_Xor.txt
You will end up with this
PHP Code:
__device__ void KeySchedule07_Xor(BYTE *ksfull, const BYTE *Cw8)
{
    
//contains cw0..7
    
const BYTE *cw Cw8;

    
ksfull[0] = ^ (((cw[5] & 0x10) **** 4) | ((cw[6] & 0x40) **** 5) | ((cw[7] & 0x2) << 1) | ((cw[0] & 0x1) << 3) | (cw[1] & 0x10) | ((cw[7] & 0x10) << 1) | (cw[4] & 0x40) | ((cw[1] & 0x20) << 2));
    
ksfull[1] = ^ (((cw[2] & 0x10) **** 4) | (cw[6] & 0x2) | (cw[5] & 0x4) | ((cw[7] & 0x80) **** 4) | (cw[6] & 0x10) | (cw[3] & 0x20) | ((cw[4] & 0x1) << 6) | ((cw[1] & 0x2) << 6));
    
ksfull[2] = ^ (((cw[6] & 0x8) **** 3) | (cw[0] & 0x2) | ((cw[5] & 0x8) **** 1) | ((cw[3] & 0x80) **** 4) | ((cw[4] & 0x4) << 2) | ((cw[3] & 0x1) << 5) | ((cw[7] & 0x4) << 4) | ((cw[2] & 0x4) << 5));
    
ksfull[3] = ^ (((cw[3] & 0x2) **** 1) | ((cw[0] & 0x40) **** 5) | ((cw[2] & 0x80) **** 5) | (cw[0] & 0x8) | ((cw[7] & 0x20) **** 1) | ((cw[3] & 0x8) << 2) | ((cw[4] & 0x10) << 2) | ((cw[3] & 0x10) << 3));
    
ksfull[4] = ^ ((cw[2] & 0x1) | ((cw[5] & 0x1) << 1) | ((cw[2] & 0x20) **** 3) | ((cw[5] & 0x80) **** 4) | ((cw[4] & 0x20) **** 1) | ((cw[4] & 0x80) **** 2) | ((cw[1] & 0x4) << 4) | ((cw[5] & 0x2) << 6));
    
ksfull[5] = ^ (((cw[4] & 0x8) **** 3) | ((cw[0] & 0x4) **** 1) | (cw[6] & 0x4) | ((cw[0] & 0x10) **** 1) | ((cw[1] & 0x80) **** 3) | ((cw[6] & 0x1) << 5) | ((cw[2] & 0x8) << 3) | ((cw[3] & 0x40) << 1));
    
ksfull[6] = ^ (((cw[0] & 0x20) **** 5) | ((cw[3] & 0x4) **** 1) | ((cw[7] & 0x40) **** 4) | ((cw[2] & 0x2) << 2) | ((cw[6] & 0x20) **** 1) | ((cw[7] & 0x8) << 2) | ((cw[5] & 0x20) << 1) | ((cw[1] & 0x1) << 7));
    
ksfull[7] = ^ (((cw[4] & 0x2) **** 1) | ((cw[2] & 0x40) **** 5) | ((cw[1] & 0x8) **** 1) | ((cw[6] & 0x80) **** 4) | ((cw[7] & 0x1) << 4) | ((cw[1] & 0x40) **** 1) | ((cw[0] & 0x80) **** 1) | ((cw[5] & 0x40) << 1));

    
ksfull[8] = ^ (((cw[3] & 0x80) **** 7) | ((cw[0] & 0x8) **** 2) | ((cw[1] & 0x1) << 2) | (cw[2] & 0x8) | ((cw[6] & 0x40) **** 2) | ((cw[1] & 0x2) << 4) | ((cw[4] & 0x20) << 1) | ((cw[7] & 0x4) << 5));
    
ksfull[9] = ^ (((cw[4] & 0x2) **** 1) | ((cw[1] & 0x40) **** 5) | ((cw[5] & 0x2) << 1) | ((cw[3] & 0x1) << 3) | ((cw[5] & 0x20) **** 1) | ((cw[1] & 0x8) << 2) | (cw[7] & 0x40) | ((cw[7] & 0x20) << 2));
    
ksfull[10] = ^ (((cw[1] & 0x20) **** 5) | ((cw[3] & 0x8) **** 2) | ((cw[2] & 0x2) << 1) | ((cw[4] & 0x40) **** 3) | ((cw[5] & 0x1) << 4) | ((cw[5] & 0x80) **** 2) | ((cw[4] & 0x4) << 4) | ((cw[6] & 0x8) << 4));
    
ksfull[11] = ^ (((cw[3] & 0x40) **** 6) | ((cw[4] & 0x10) **** 3) | ((cw[2] & 0x1) << 2) | ((cw[5] & 0x40) **** 3) | ((cw[5] & 0x4) << 2) | ((cw[7] & 0x80) **** 2) | ((cw[1] & 0x10) << 2) | ((cw[1] & 0x4) << 5));
    
ksfull[12] = ^ (((cw[0] & 0x80) **** 7) | ((cw[2] & 0x80) **** 6) | ((cw[4] & 0x8) **** 1) | (cw[5] & 0x8) | (cw[6] & 0x10) | (cw[6] & 0x20) | ((cw[4] & 0x80) **** 1) | ((cw[7] & 0x8) << 4));
    
ksfull[13] = ^ (((cw[2] & 0x4) **** 2) | ((cw[6] & 0x80) **** 6) | (cw[0] & 0x4) | ((cw[0] & 0x2) << 2) | (cw[3] & 0x10) | ((cw[5] & 0x10) << 1) | (cw[0] & 0x40) | ((cw[0] & 0x10) << 3));
    
ksfull[14] = ^ (((cw[1] & 0x80) **** 7) | ((cw[4] & 0x1) << 1) | ((cw[7] & 0x2) << 1) | ((cw[3] & 0x20) **** 2) | ((cw[6] & 0x1) << 4) | (cw[0] & 0x20) | ((cw[0] & 0x1) << 6) | ((cw[7] & 0x1) << 7));
    
ksfull[15] = ^ (((cw[3] & 0x4) **** 2) | ((cw[2] & 0x10) **** 3) | ((cw[2] & 0x20) **** 3) | ((cw[7] & 0x10) **** 1) | ((cw[6] & 0x2) << 3) | ((cw[6] & 0x4) << 3) | (cw[2] & 0x40) | ((cw[3] & 0x2) << 6));

    
ksfull[16] = ^ (((cw[4] & 0x40) **** 6) | ((cw[5] & 0x40) **** 5) | ((cw[7] & 0x1) << 2) | ((cw[0] & 0x40) **** 3) | ((cw[0] & 0x8) << 1) | (cw[7] & 0x20) | ((cw[6] & 0x10) << 2) | ((cw[4] & 0x4) << 5));
    
ksfull[17] = ^ (((cw[3] & 0x4) **** 2) | ((cw[6] & 0x4) **** 1) | ((cw[7] & 0x8) **** 1) | ((cw[5] & 0x80) **** 4) | ((cw[0] & 0x1) << 4) | (cw[2] & 0x20) | ((cw[7] & 0x2) << 5) | ((cw[5] & 0x4) << 5));
    
ksfull[18] = ^ (((cw[7] & 0x4) **** 2) | ((cw[7] & 0x80) **** 6) | ((cw[3] & 0x20) **** 3) | ((cw[4] & 0x20) **** 2) | ((cw[2] & 0x80) **** 3) | ((cw[5] & 0x8) << 2) | ((cw[5] & 0x1) << 6) | ((cw[1] & 0x20) << 2));
    
ksfull[19] = ^ (((cw[0] & 0x10) **** 4) | ((cw[1] & 0x10) **** 3) | ((cw[0] & 0x80) **** 5) | ((cw[3] & 0x2) << 2) | ((cw[5] & 0x2) << 3) | ((cw[3] & 0x1) << 5) | (cw[6] & 0x40) | (cw[4] & 0x80));
    
ksfull[20] = ^ (((cw[2] & 0x40) **** 6) | ((cw[2] & 0x1) << 1) | (cw[2] & 0x4) | ((cw[2] & 0x2) << 2) | ((cw[5] & 0x20) **** 1) | ((cw[6] & 0x1) << 5) | ((cw[6] & 0x20) << 1) | ((cw[0] & 0x20) << 2));
    
ksfull[21] = ^ (((cw[6] & 0x8) **** 3) | ((cw[7] & 0x10) **** 3) | ((cw[6] & 0x80) **** 5) | (cw[3] & 0x8) | ((cw[1] & 0x4) << 2) | ((cw[3] & 0x80) **** 2) | ((cw[4] & 0x10) << 2) | ((cw[0] & 0x2) << 6));
    
ksfull[22] = ^ (((cw[3] & 0x10) **** 4) | ((cw[7] & 0x40) **** 5) | ((cw[1] & 0x1) << 2) | (cw[1] & 0x8) | (cw[5] & 0x10) | ((cw[1] & 0x80) **** 2) | ((cw[2] & 0x8) << 3) | ((cw[6] & 0x2) << 6));
    
ksfull[23] = ^ ((cw[4] & 0x1) | (cw[4] & 0x2) | ((cw[4] & 0x8) **** 1) | ((cw[1] & 0x2) << 2) | ((cw[1] & 0x40) **** 2) | ((cw[0] & 0x4) << 3) | ((cw[2] & 0x10) << 2) | ((cw[3] & 0x40) << 1));

    
ksfull[24] = ^ (((cw[4] & 0x20) **** 5) | (cw[3] & 0x2) | ((cw[6] & 0x2) << 1) | ((cw[4] & 0x10) **** 1) | ((cw[5] & 0x40) **** 2) | ((cw[5] & 0x4) << 3) | ((cw[5] & 0x20) << 1) | ((cw[5] & 0x1) << 7));
    
ksfull[25] = ^ ((cw[4] & 0x1) | ((cw[0] & 0x4) **** 1) | ((cw[0] & 0x20) **** 3) | (cw[5] & 0x8) | ((cw[2] & 0x8) << 1) | ((cw[4] & 0x8) << 2) | ((cw[1] & 0x1) << 6) | ((cw[5] & 0x2) << 6));
    
ksfull[26] = ^ (((cw[4] & 0x4) **** 2) | ((cw[3] & 0x1) << 1) | ((cw[1] & 0x8) **** 1) | ((cw[6] & 0x10) **** 1) | ((cw[2] & 0x1) << 4) | ((cw[2] & 0x2) << 4) | ((cw[2] & 0x80) **** 1) | ((cw[7] & 0x4) << 5));
    
ksfull[27] = ^ (((cw[0] & 0x2) **** 1) | ((cw[6] & 0x40) **** 5) | ((cw[2] & 0x40) **** 4) | ((cw[3] & 0x40) **** 3) | ((cw[7] & 0x8) << 1) | ((cw[5] & 0x80) **** 2) | ((cw[0] & 0x8) << 3) | ((cw[6] & 0x20) << 2));
    
ksfull[28] = ^ (((cw[2] & 0x10) **** 4) | ((cw[0] & 0x80) **** 6) | ((cw[6] & 0x8) **** 1) | ((cw[3] & 0x20) **** 2) | ((cw[0] & 0x1) << 4) | ((cw[5] & 0x10) << 1) | ((cw[6] & 0x1) << 6) | (cw[1] & 0x80));
    
ksfull[29] = ^ (((cw[1] & 0x20) **** 5) | (cw[1] & 0x2) | ((cw[7] & 0x10) **** 2) | ((cw[7] & 0x80) **** 4) | ((cw[4] & 0x80) **** 3) | ((cw[4] & 0x40) **** 1) | ((cw[1] & 0x10) << 2) | ((cw[3] & 0x8) << 4));
    
ksfull[30] = ^ (((cw[1] & 0x4) **** 2) | (cw[7] & 0x2) | ((cw[7] & 0x1) << 2) | ((cw[2] & 0x20) **** 2) | ((cw[3] & 0x80) **** 3) | ((cw[3] & 0x10) << 1) | (cw[0] & 0x40) | ((cw[1] & 0x40) << 1));
    
ksfull[31] = ^ (((cw[7] & 0x40) **** 6) | ((cw[3] & 0x4) **** 1) | (cw[2] & 0x4) | ((cw[7] & 0x20) **** 2) | ((cw[6] & 0x4) << 2) | ((cw[6] & 0x80) **** 2) | ((cw[4] & 0x2) << 5) | ((cw[0] & 0x10) << 3));

    
ksfull[32] = ^ (((cw[6] & 0x10) **** 4) | ((cw[3] & 0x40) **** 5) | ((cw[1] & 0x40) **** 4) | ((cw[1] & 0x10) **** 1) | ((cw[3] & 0x2) << 3) | ((cw[5] & 0x2) << 4) | ((cw[0] & 0x1) << 6) | (cw[2] & 0x80));
    
ksfull[33] = ^ (((cw[7] & 0x40) **** 6) | ((cw[6] & 0x80) **** 6) | ((cw[1] & 0x80) **** 5) | ((cw[2] & 0x2) << 2) | ((cw[0] & 0x40) **** 2) | ((cw[2] & 0x4) << 3) | ((cw[7] & 0x1) << 6) | ((cw[7] & 0x8) << 4));
    
ksfull[34] = ^ ((cw[5] & 0x1) | ((cw[5] & 0x80) **** 6) | ((cw[2] & 0x20) **** 3) | ((cw[5] & 0x20) **** 2) | ((cw[0] & 0x80) **** 3) | (cw[3] & 0x20) | ((cw[2] & 0x1) << 6) | ((cw[4] & 0x4) << 5));
    
ksfull[35] = ^ (((cw[3] & 0x8) **** 3) | ((cw[0] & 0x8) **** 2) | ((cw[2] & 0x10) **** 2) | ((cw[0] & 0x10) **** 1) | ((cw[0] & 0x20) **** 1) | ((cw[5] & 0x8) << 2) | (cw[5] & 0x40) | ((cw[6] & 0x1) << 7));
    
ksfull[36] = ^ (((cw[4] & 0x2) **** 1) | ((cw[2] & 0x40) **** 5) | ((cw[1] & 0x20) **** 3) | (cw[1] & 0x8) | ((cw[2] & 0x8) << 1) | ((cw[3] & 0x80) **** 2) | ((cw[5] & 0x10) << 2) | ((cw[3] & 0x10) << 3));
    
ksfull[37] = ^ (((cw[7] & 0x4) **** 2) | ((cw[7] & 0x20) **** 4) | ((cw[1] & 0x2) << 1) | ((cw[3] & 0x1) << 3) | ((cw[6] & 0x20) **** 1) | (cw[4] & 0x20) | (cw[6] & 0x40) | (cw[7] & 0x80));
    
ksfull[38] = ^ (((cw[4] & 0x80) **** 7) | ((cw[1] & 0x1) << 1) | ((cw[6] & 0x2) << 1) | (cw[4] & 0x8) | ((cw[4] & 0x40) **** 2) | ((cw[1] & 0x4) << 3) | ((cw[4] & 0x10) << 2) | ((cw[6] & 0x4) << 5));
    
ksfull[39] = ^ (((cw[7] & 0x2) **** 1) | ((cw[4] & 0x1) << 1) | ((cw[6] & 0x8) **** 1) | ((cw[5] & 0x4) << 1) | ((cw[0] & 0x4) << 2) | ((cw[7] & 0x10) << 1) | ((cw[3] & 0x4) << 4) | ((cw[0] & 0x2) << 6));

    
ksfull[40] = ^ (((cw[5] & 0x20) **** 5) | ((cw[0] & 0x10) **** 3) | (cw[6] & 0x4) | ((cw[6] & 0x40) **** 3) | ((cw[3] & 0x40) **** 2) | ((cw[7] & 0x8) << 2) | ((cw[2] & 0x8) << 3) | ((cw[2] & 0x1) << 7));
    
ksfull[41] = ^ (((cw[7] & 0x2) **** 1) | ((cw[7] & 0x10) **** 3) | ((cw[3] & 0x10) **** 2) | ((cw[3] & 0x20) **** 2) | (cw[4] & 0x10) | ((cw[6] & 0x8) << 2) | ((cw[6] & 0x2) << 5) | ((cw[0] & 0x20) << 2));
    
ksfull[42] = ^ (((cw[2] & 0x80) **** 7) | ((cw[5] & 0x8) **** 2) | ((cw[4] & 0x8) **** 1) | ((cw[0] & 0x1) << 3) | ((cw[2] & 0x40) **** 2) | ((cw[1] & 0x8) << 2) | ((cw[0] & 0x80) **** 1) | ((cw[5] & 0x1) << 7));
    
ksfull[43] = ^ (((cw[7] & 0x80) **** 7) | ((cw[5] & 0x40) **** 5) | ((cw[4] & 0x2) << 1) | ((cw[0] & 0x2) << 2) | ((cw[1] & 0x80) **** 3) | ((cw[2] & 0x2) << 4) | ((cw[3] & 0x2) << 5) | ((cw[5] & 0x10) << 3));
    
ksfull[44] = ^ (((cw[3] & 0x4) **** 2) | ((cw[2] & 0x10) **** 3) | (cw[7] & 0x4) | ((cw[2] & 0x20) **** 2) | ((cw[0] & 0x40) **** 2) | ((cw[4] & 0x40) **** 1) | ((cw[3] & 0x80) **** 1) | ((cw[1] & 0x4) << 5));
    
ksfull[45] = ^ (((cw[4] & 0x4) **** 2) | ((cw[5] & 0x4) **** 1) | ((cw[7] & 0x20) **** 3) | ((cw[5] & 0x80) **** 4) | ((cw[6] & 0x1) << 4) | ((cw[6] & 0x10) << 1) | ((cw[0] & 0x8) << 3) | ((cw[3] & 0x1) << 7));
    
ksfull[46] = ^ (((cw[6] & 0x20) **** 5) | ((cw[7] & 0x1) << 1) | ((cw[1] & 0x40) **** 4) | ((cw[2] & 0x4) << 1) | ((cw[4] & 0x20) **** 1) | ((cw[4] & 0x80) **** 2) | ((cw[1] & 0x10) << 2) | ((cw[0] & 0x4) << 5));
    
ksfull[47] = ^ ((cw[1] & 0x1) | ((cw[7] & 0x40) **** 5) | ((cw[1] & 0x20) **** 3) | ((cw[5] & 0x2) << 2) | ((cw[6] & 0x80) **** 3) | ((cw[1] & 0x2) << 4) | ((cw[4] & 0x1) << 6) | ((cw[3] & 0x8) << 4));

    
ksfull[48] = cw[0];
    
ksfull[49] = cw[1];
    
ksfull[50] = cw[2];
    
ksfull[51] = cw[3];
    
ksfull[52] = cw[4];
    
ksfull[53] = cw[5];
    
ksfull[54] = cw[6];
    
ksfull[55] = cw[7];
}
#endif 
People Beware that the forum is not CODE Friendly. Wenever You have @ or two consecutive > as in "> >" without space it changes to "****"

So when you see the code just imagine you see "> >" without space between, and Not "****"

So void KeySchedule07_Xor(BYTE *ksfull, const BYTE *Cw8)

This mean Input is Cw8, output is ksfull.

Looking at left you see

Code:
ksfull[0] = 0 ^ (( blabla...

***

ksfull[48] = 6 ^ cw[0];
    ksfull[49] = 6 ^ cw[1];
    ksfull[50] = 6 ^ cw[2];
    ksfull[51] = 6 ^ cw[3];
    ksfull[52] = 6 ^ cw[4];
    ksfull[53] = 6 ^ cw[5];
    ksfull[54] = 6 ^ cw[6];
    ksfull[55] = 6 ^ cw[7];
See the original Keys at the end!!

Now lets see what a line of code do.
Reply With Quote
The Following User Says Thank You to cayoenrique For This Useful Post:
Me2019H (15-01-2022)
  #9  
Old 15-01-2022, 07:15  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
cayoenrique cayoenrique is offline
Linux advisor
Senior Member
 
Join Date: May 2018
Posts: 500
Thanks: 319
Thanked 764 Times in 279 Posts
Country: Country Flag
Default

Now lets look at one line

Code:
ksfull[0] = 0 ^ (((cw[5] & 0x10) **** 4) | ((cw[6] & 0x40) **** 5) | ((cw[7] & 0x2) << 1) | ((cw[0] & 0x1) << 3) | (cw[1] & 0x10) | ((cw[7] & 0x10) << 1) | (cw[4] & 0x40) | ((cw[1] & 0x20) << 2));
This is take this template
Code:
ksfull[0] = 0 ^ ( ( eq1 ) | ( eq2 ) | ( eq3 ) | ( eq4 ) | ( eq5 ) | ( eq6 ) | ( eq7 ) | ( eq8 ) );
See there 8 eq one for each bit in a byte. What this is doing is selecting a bit of the TOTAL 65 bit CW and shifting it around to another position.

So how we select bits on C. We do bitwise-and operation
Code:
(cw[5] & 0x10)
this is of the form
Code:
Byte & (bit position)

So in the previous we are saying.
Byte is cw[5].
Bit position is 0x10.

lets see this in binary. Lets give value to cw[5]= 0x8F

0x8F = 1000 1111
0x10 = 0001 0000

And we want to do and & And.
This means that to be 1 both bits has to have 1. If out bit selector ONLY have one bit with 1 as result we will optain the but value from it source.

0x8F = 1000 1111
&
0x10 = 0001 0000
-------------------
0x00 = 0000 0000

Now imagine original is cw[5] = 0xFF
0xFF = 1111 1111
&
0x10 = 0001 0000
-------------------
0x01 = 0001 0000

Ahhaaa see now the result shows the value of the bit 5 position in cw[5]. As result this is a bit select operation.

Now the original Idea is to move that bit to a new position.

(cw[5] & 0x10) > > 4) where "> >" no space means me bit X positions to the right. To move to the left we do "<<".

Again if cw[5] = 0xFF then we take our result and do "> >" 4

( 0001 0000 ) "> >" 4 = 0000 0001

See it is easy. We do a bitwise-and to select bit. Then we do a bitwise-move to shift bit to new position. We do 8 bitwise-or to finally add the result of all bits to construct our new byte.

Last is the symbol | . This is a bitwise-or operation. This is used to add all 8 bit that we move to end up with a new byte. Let me show you with two bits

0001 0000 | 0010 0000 = 0011 0000

Now lets do it with 8 bits

Code:
0xAA = 1010 1010 = 0000 0000 | 0000 0010 | 0000 0000 | 0000 1000 | 0000 0000 | 0010 0000 | 0000 0000 | 1000 0000
Reply With Quote
The Following 2 Users Say Thank You to cayoenrique For This Useful Post:
dvlajkovic (15-01-2022), Me2019H (15-01-2022)
  #10  
Old 15-01-2022, 12:19  Translate from English to Italian  Translate from English to French  Translate from English to German  Translate from English to Spanish  Translate from English to Dutch  Translate from English to Greek  Translate from English to Portuguese  Translate from English to Russian  Translate from English to Russian
Me2019H Me2019H is offline
Senior Member
 
Join Date: Dec 2019
Posts: 43
Thanks: 66
Thanked 9 Times in 8 Posts
Country: Country Flag
Default

Hello,
Thank you very much cayoenrique

I know programming, I know variables and their types, even if the C is new, I will not find an obstacle. I will search in the Internet
And I know that memory consists of zeros and ones, and to make it easier we use hexadecimal 2^n.

Code:
int argc, char *argv[] Ignore this complex form but this are called Arguments. Are values or variables we pass to the subroutine. This are the Inputs.
This is new to me but I understand it

the argc represent tne number of things that we enter in command line when running the program
argv[] is an array holds the string values of the the things that were entred on the command line when running the program

gcc ./example cayoenrique

argc=2
argv[0]=./example
argv[1]=cayoenrique



if i understand what i want to do i will translate it to a code that's why i'm asking to understand the algo how it works by understanding the code it's beter to add some comments in each part of code,please

I apologize for the many questions i ask, what I want is to learn so that i can program the algorithms on my own in the future

Last edited by Me2019H; 15-01-2022 at 12:34..
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:32.


Powered by vBulletin
Copyright ©2006-2019 - Sat Universe