Reading 2 numbers in assembly and storing it in a variable - variables

just to put it out there -I really did search and try to find an easy to understand tutorial but couldn't :/ .. I'm still kind of new to it.
But what I'm struggling with is to input 2 numbers from the user and to store it in a variable . And then later compare it to a Maximum value.
output db 10,13, "Enter a number: $"
asq dw 10,13, "$" ; ascii values for a new line
stilltoimplement db 10,13, "Do calculations $"
.code
jmp start
number db ?
max db 14
start:
mov ax,#data
mov ds,ax
mov ah,09 ;prints new line
mov dx, offset output
int 21h
mov ah, 01 ;checks for key
mov al, 01
int 21h
mov number, al
cmp number,14
jg start
jl part2
part2:
mov ah,09
mov dx,offset stilltoimplement
int 21h
ending:
mov ah,4ch
mov al,00
int 21h ;End the program
END

If you want to add multiple-digit numbers, you could store the digits
in a register by multiplying the current number by 10 on a digit
input.
I would guess that you are on x86 so you have 6 general purpose
registers.
In assembler-like pseudocode:
register a = 0
register b = 0
register c = 0
num1:
c = getDigit()
if c is a delimiter/sentinel value jump to num2
a = a * 10
a = a + c
jump to num1
num2:
c = getDigit()
if c is a delimiter/sentinel value jump to sum
b = b * 10
b = b + c
jump to num2
sum:
a = a + b
and your sum is now in a

Related

Is there an algorithm, to find values ​of a polynomial with big integers, quickly without loops?

For example, if I want to find
1085912312763120759250776993188102125849391224162 = a^9+b^9+c^9+d
the code needs to brings
a=3456
b=78525
c=217423
d=215478
I do not need specific values, only that they comply with the fact that a, b and c have 6 digits at most and d is as small as possible.
Is there a quick way to find it?
I appreciate any help you can give me.
I have tried with nested loops but it is extremely slow and the code gets stuck.
Any help in VB or other code would be appreciated. I think the structure is more important than the language in this case
Imports System.Numerics
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Value As BigInteger = BigInteger.Parse("1085912312763120759250776993188102125849391224162")
Dim powResult As BigInteger
Dim dResult As BigInteger
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
For i = 1 To 999999
For j = 1 To 999999
For k = 1 To 999999
powResult = BigInteger.Add(BigInteger.Add(BigInteger.Pow(i, 9), BigInteger.Pow(j, 9)), BigInteger.Pow(k, 9))
dResult = BigInteger.Subtract(Value, powResult)
If Len(dResult.ToString) <= 6 Then
a = i
b = j
c = k
d = dResult
RichTextBox1.Text = a & " , " & b & " , " & c & " , " & d
Exit For
Exit For
Exit For
End If
Next
Next
Next
End Sub
End Class
UPDATE
I wrote the code in vb. But with this code, a is correct, b is correct but c is incorrect, and the result is incorrect.
a^9 + b^9 + c^9 + d is a number bigger than the initial value.
The code should brings
a= 217423
b= 78525
c= 3456
d= 215478
Total Value is ok= 1085912312763120759250776993188102125849391224162
but code brings
a= 217423
b= 78525
c= 65957
d= 70333722607339201875244531009974
Total Value is bigger and not equal=1085935936469985777155428248430866412402362281319
Whats i need to change in the code to make c= 3456 and d= 215478?
the code is
Imports System.Numerics
Public Class Form1
Private Function pow9(x As BigInteger) As BigInteger
Dim y As BigInteger
y = x * x ' x^2
y *= y ' x^4
y *= y ' x^8
y *= x ' x^9
Return y
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim a, b, c, d, D2, n As BigInteger
Dim aa, bb, cc, dd, ae As BigInteger
D2 = BigInteger.Parse("1085912312763120759250776993188102125849391224162")
'first solution so a is maximal
d = D2
'a = BigIntegerSqrt(D2)
'RichTextBox1.Text = a.ToString
For a = 1 << ((Convert.ToInt32(Math.Ceiling(BigInteger.Log(d, 2))) + 8) / 9) To a > 0 Step -1
If (pow9(a) <= d) Then
d -= pow9(a)
Exit For
End If
Next
For b = 1 << ((Convert.ToInt32(Math.Ceiling(BigInteger.Log(d, 2))) + 8) / 9) To b > 0 Step -1
If (pow9(b) <= d) Then
d -= pow9(b)
Exit For
End If
Next
For c = 1 << ((Convert.ToInt32(Math.Ceiling(BigInteger.Log(d, 2))) + 8) / 9) To c > 0 Step -1
If (pow9(c) <= d) Then
d -= pow9(c)
Exit For
End If
Next
' minimize d
aa = a
bb = b
cc = c
dd = d
If (aa < 10) Then
ae = 0
Else
ae = aa - 10
End If
For a = aa - 1 To a > ae Step -1 'a goes down few iterations
d = D2 - pow9(a)
For n = 1 << ((Convert.ToInt32(Math.Ceiling(BigInteger.Log(d, 2))) + 8) / 9) To b < n 'b goes up
If (pow9(b) >= d) Then
b = b - 1
d -= pow9(b)
Exit For
End If
Next
For c = 1 << ((Convert.ToInt32(Math.Ceiling(BigInteger.Log(d, 2))) + 8) / 9) To c > 0 Step -1 'c must be search fully
If pow9(c) <= d Then
d -= pow9(c)
Exit For
End If
Next
If d < dd Then 'remember better solution
aa = a
bb = b
cc = c
dd = d
End If
If a < ae Then
Exit For
End If
Next
a = aa
b = bb
c = cc
d = dd
' a,b,c,d is the result
RichTextBox1.Text = D2.ToString
Dim Sum As BigInteger
Dim a9 As BigInteger
Dim b9 As BigInteger
Dim c9 As BigInteger
a9 = BigInteger.Pow(a, 9)
b9 = BigInteger.Pow(b, 9)
c9 = BigInteger.Pow(c, 9)
Sum = BigInteger.Add(BigInteger.Add(BigInteger.Add(a9, b9), c9), d)
RichTextBox2.Text = Sum.ToString
Dim Subst As BigInteger
Subst = BigInteger.Subtract(Sum, D2)
RichTextBox3.Text = Subst.ToString
End Sub
End Class
[Update]
The below code is an attempt to solve a problem like OP's, yet I erred in reading it.
The below is for 1085912312763120759250776993188102125849391224162 = a^9+b^9+c^9+d^9+e and to minimize e.
Just became too excite about OP's interesting conundrum and read too quick.
I review this more later.
OP's approach is O(N*N*N*N) - slow
Below is a O(N*N*log(N)) one.
Algorithm
Let N = 1,000,000. (Looks like 250,000 is good enough for OP's sum of 1.0859e48.)
Define 160+ wide integer math routines.
Define type: pow9
int x,y,
int160least_t z
Form array pow9 a[N*N] populated with x, y, x^9 + y^9, for every x,y in the [1...N] range.
Sort array on z.
Cost so far O(N*N*log(N).
For array elements indexed [0... N*N/2] do a binary search for another array element such that the sum is 1085912312763120759250776993188102125849391224162
Sum closest is the answer.
Time: O(N*N*log(N))
Space: O(N*N)
Easy to start with FP math and then later get a better answer with crafter extended integer math.
Try with smaller N and total sum targets to iron out implementation issues.
In case a,b,c,d might be zero I got an Idea for fast and simple solution:
First something better than brute force search of a^9 + d = x so that a is maximal (that ensures minimal d)...
let d = 1085912312763120759250776993188102125849391224162
find max value a such that a^9 <= d
this is simple as we know 9th power will multiply the bitwidth of operand 9 times so the max value can be at most a <= 2^(log2(d)/9) Now just search all numbers from this number down to zero (decrementing) until its 9th power is less or equal to x. This value will be our a.
Its still brute force search however from much better starting point so much less iterations are required.
We also need to update d so let
d = d - a^9
Now just find b,c in the same way (using smaller and smaller remainder d)... these searches are not nested so they are fast ...
b^9 <= d; d-=b^9;
c^9 <= d; c-=b^9;
To improve speed even more you can hardcode the 9th power using power by squaring ...
This will be our initial solution (on mine setup it took ~200ms with 32*8 bits uints) with these results:
x = 1085912312763120759250776993188102125849391224162
1085912312763120759250776993188102125849391224162 (reference)
a = 217425
b = 65957
c = 22886
d = 39113777348346762582909125401671564
Now we want to minimize d so simply decrement a and search b upwards until still a^9 + b^9 <= d is lower. Then search c as before and remember better solution. The a should be search downwards to meet b in the middle but as both a and bhave the same powers only few iterations might suffice (I used 50) from the first solution (but I have no proof of this its just my feeling). But still even if full range is used this has less complexity than yours as I have just 2 nested fors instead of yours 3 and they all are with lower ranges...
Here small working C++ example (sorry do not code in BASIC for decades):
//---------------------------------------------------------------------------
typedef uint<8> bigint;
//---------------------------------------------------------------------------
bigint pow9(bigint &x)
{
bigint y;
y=x*x; // x^2
y*=y; // x^4
y*=y; // x^8
y*=x; // x^9
return y;
}
//---------------------------------------------------------------------------
void compute()
{
bigint a,b,c,d,D,n;
bigint aa,bb,cc,dd,ae;
D="1085912312763120759250776993188102125849391224162";
// first solution so a is maximal
d=D;
for (a=1<<((d.bits()+8)/9);a>0;a--) if (pow9(a)<=d) break; d-=pow9(a);
for (b=1<<((d.bits()+8)/9);b>0;b--) if (pow9(b)<=d) break; d-=pow9(b);
for (c=1<<((d.bits()+8)/9);c>0;c--) if (pow9(c)<=d) break; d-=pow9(c);
// minimize d
aa=a; bb=b; cc=c; dd=d;
if (aa<50) ae=0; else ae=aa-50;
for (a=aa-1;a>ae;a--) // a goes down few iterations
{
d=D-pow9(a);
for (n=1<<((d.bits()+8)/9),b++;b<n;b++) if (pow9(b)>=d) break; b--; d-=pow9(b); // b goes up
for (c=1<<((d.bits()+8)/9);c>0;c--) if (pow9(c)<=d) break; d-=pow9(c); // c must be search fully
if (d<dd) // remember better solution
{
aa=a; bb=b; cc=c; dd=d;
}
}
a=aa; b=bb; c=cc; d=dd; // a,b,c,d is the result
}
//-------------------------------------------------------------------------
The function bits() just returns number of occupied bits (similar to log2 but much faster). Here final results:
x = 1085912312763120759250776993188102125849391224162
1085912312763120759250776993188102125849391224162 (reference)
a = 217423
b = 78525
c = 3456
d = 215478
It took 1689.651 ms ... As you can see this is much faster than yours however I am not sure with the number of search iterations while fine tuning ais OK or it should be scaled by a/b or even full range down to (a+b)/2 which will be much slower than this...
One last thing I did not bound a,b,c to 999999 so if you want it you just add if (a>999999) a=999999; statement after any a=1<<((d.bits()+8)/9)...
[Edit1] adding binary search
Ok now all the full searches for 9th root (except of the fine tunnig of a) can be done with binary search which will improve speed a lot more while ignoring bigint multiplication complexity leads to O(n.log(n)) against your O(n^3)... Here updated code (will full iteration of a while fitting so its safe):
//---------------------------------------------------------------------------
typedef uint<8> bigint;
//---------------------------------------------------------------------------
bigint pow9(bigint &x)
{
bigint y;
y=x*x; // x^2
y*=y; // x^4
y*=y; // x^8
y*=x; // x^9
return y;
}
//---------------------------------------------------------------------------
bigint binsearch_max_pow9(bigint &d) // return biggest x, where x^9 <= d, and lower d by x^9
{ // x = floor(d^(1/9)) , d = remainder
bigint m,x;
for (m=bigint(1)<<((d.bits()+8)/9),x=0;m.isnonzero();m>>=1)
{ x|=m; if (pow9(x)>d) x^=m; }
d-=pow9(x);
return x;
}
//---------------------------------------------------------------------------
void compute()
{
bigint a,b,c,d,D,n;
bigint aa,bb,cc,dd;
D="1085912312763120759250776993188102125849391224162";
// first solution so a is maximal
d=D;
a=binsearch_max_pow9(d);
b=binsearch_max_pow9(d);
c=binsearch_max_pow9(d);
// minimize d
aa=a; bb=b; cc=c; dd=d;
for (a=aa-1;a>=b;a--) // a goes down few iterations
{
d=D-pow9(a);
for (n=1<<((d.bits()+8)/9),b++;b<n;b++) if (pow9(b)>=d) break; b--; d-=pow9(b); // b goes up
c=binsearch_max_pow9(d);
if (d<dd) // remember better solution
{
aa=a; bb=b; cc=c; dd=d;
}
}
a=aa; b=bb; c=cc; d=dd; // a,b,c,d is the result
}
//-------------------------------------------------------------------------
function m.isnonzero() is the same as m!=0 just faster... The results are the same as above code but the time duration is only 821 ms for full iteration of a which would be several thousands seconds with previous code.
I think except using some polynomial discrete math trick I do not know of there is only one more thing to improve and that is to compute consequent pow9 without multiplication which will boost the speed a lot (as bigint multiplication is slowest operation by far) like I did in here:
How to get a square root for 32 bit input in one clock cycle only?
but I am too lazy to derive it...

Refer to field and assign some logic to that field

I have input file with data as
cell input out type fun level
AI20 A1,A2,A3 Z comb ((A1A2)) 2
INV I1 ZN comb (!I1) 1
BUF A1,A2,A3,B1 Z comb (!(((A1A2)A3)B1)) 4
CLK C Z seq Cq 1
XOR A1,A2,B1 Z comb (((A1A2)B1) 3
IAD A1,A2,A3 Z comb (!((A1A2)A3)) 3
INV I1 ZN comb (!I1) 1
I want output as below
cell ins input out
AI20 i1 .A1(A),.A2(B),.A3(C) .Z(n1)
INV i2 .I1(n1) .ZN(n2)
BUF i3 .A1(n2),.A2(1),.A3(0),.B1(0) .Z(n3)
CLK i4 .C(n3) .Z(n4)
XOR i5 .A1(n4),.A2(0),.B1(0) .Z(n5)
IAD i6 .A1(1),.A2(n5),.A3(0) .Z(n6)
INV i7 .I1(n6) .ZN(X)
The logic is
if it is first line of input file I.e AI20 assign its inputs A1,A2 to user defined A and B and assign it output to n1. For next line in input file assign previous net n1 to one of input and 0/1 to other inputs of that line and assign its output to next net n2 and so on. n1, n2,n3 so on are nets and can be assigned to an array which has no. Of rows equal to no of rows in (input file)-1(no. of rows exclude header row of input file). If it is last line or row of input file then assign that line or row output to X.
i1,i2,i3... are instance name which has number of rows equal to no of rows of (input file).
A,B,X are user defined. We can directly use them in code. The term inside bracket for input is basically the one present in the previous line in output(). Exception will be for first line input and last line output whose () terms are directly defined.
I used code
awk ' { print $1 ;print "."$2"()"; print "."$3"()" file }'
This gives me, but how can I build logic for inside().
AI20 .A1(), .A2(),.A3() .Z()
You may use this awk script:
cat remap.awk
NR == 1 {
print "cell ins input out"
next
}
id != "" {
++r
print id, "i" r, s, "." out "(n" r ")"
}
{
n = split($2, a, /,/)
s = ""
if (NR == 2) {
ch = 65
for (i=1; i<=n; ++i)
s = (s == "" ? "" : s ",") sprintf(".%s(%c)", a[i], ch++)
} else {
s = "." a[1] "(n" r ")"
for (i=2; i<=n; ++i)
s = s "," sprintf(".%s(%d)", a[i], i%2)
}
id = $1
out = $3
}
END {
if (r)
print id, "i" r+1, s, "." out "(X)"
}
Then use it as:
awk -f remap.awk file.txt | column -t
cell ins input out
AI20 i1 .A1(A),.A2(B),.A3(C) .Z(n1)
INV i2 .I1(n1) .ZN(n2)
BUF i3 .A1(n2),.A2(0),.A3(1),.B1(0) .Z(n3)
CLK i4 .C(n3) .Z(n4)
XOR i5 .A1(n4),.A2(0),.B1(1) .Z(n5)
IAD i6 .A1(n5),.A2(0),.A3(1) .Z(n6)
INV i7 .I1(n6) .ZN(X)

Breaking a XOR with repeating key and counter

I was given an exercise where I have to break a xor with repeating key and counter.
I don't know the key nor its length, nor the value of the counter.
I have:
PT1 xor K = C1
PT2 xor K = C2
PT3 xor K = C3
So:
C1 xor C2 = PT1 xor PT2 xor K xor K = PT1 xor PT2 xor 0
So:
0 xor C1 xor C2 = PT1 xor PT2
0 xor C1 xor C3 = PT1 xor PT3
0 Xor C2 xor C3 = PT2 xor PT3
Where K is key, C is cypher and PT is Plain Text.
I don't know what to do with that. Could you please give me a hint? :)
Here is a solution that satisfies your conditions from with your question
PT1(5) K(9) C1(12)
PT2(7) K(9) C2(14)
PT3(9) K(9) C3(0)
0 xor C1 xor C2 = PT1 xor PT2
0 xor C1 xor C3 = PT1 xor PT3
0 Xor C2 xor C3 = PT2 xor PT3
So in the case i built:
0 xor C1(12) xor C2(14) = PT1(5) xor PT2(7)
0 xor C1(12) xor C3(0) = PT1(5) xor PT3(9)
0 Xor C2(14) xor C3(0) = PT2(7) xor PT3(9)
In weak cases you can get K like this:
You can get K like this:
In [519]: 1^5
Out[519]: 4
In [520]: 2^5
Out[520]: 7
In [521]: 3^5
Out[521]: 6
In [522]: 6^7^4
Out[522]: 5
So you can crack the key by xoring the ciphers together if a weak key to xor cipher is used ( Does not work in all cases only very rare one ). But does that help any for helping you solve the problem?
PT1 xor K = C1 if c1 is 4
PT2 xor K = C2 if c2 is 7
PT3 xor K = C3 if c2 is 6
You know that K is 5. From there you can get PT by working the XOR backwards:
c1 (4) ^ K (5) = PT1
c2 (7) ^ K (5) = PT2
c3 (6) ^ K (5) = PT3
So to recap, XOR c1^c2^c3 to get K, and from there you can get the corresponding PT(1-3). But this only works in some rare cases, but does it help?
If you have any of the values, let me know. I'll try to recreate something from scratch
Here's a case where i XORED the C1, C2, C3 together to get a key, and then PT1-3 just fill in to work
PT1(10) K(12) C1(6)
PT2(4) K(12) C2(8)
PT3(14) K(12) C3(2)
0 xor C1(6) xor C2(8) = PT1(10) xor PT2(4)
0 xor C1(6) xor C3(2) = PT1(10) xor PT3(14)
0 Xor C2(8) xor C3(2) = PT2(4) xor PT3(14)
It really depends on how your assignment is expecting you to get the key. I hope all of this helps, encryption is fun. I provided a few paths, hopefully one will help.

Why on my code that checks for permutations, Characters also permute with themselves?

So my code searches for permutations from a random given String, and checks some .txt dictionary files (which are loaded in arrays) to see the words that can be made with the random given letters. But my code also makes them permute with themselves. For instance if i put "ab" it should make these permutations "ab" and "ba". INstead it makes "aa", "ab", "ba" and "bb". Any ideas? (the given code is for words until length 3)
If TextBox1.Text.Length > 1 Then
For Each c0 As Char In chars
For Each c1 As Char In chars
For i As Integer = 0 To Rank2.Length - 1
test = Rank2(i)
If InStr(Rank2(i), c0 & c1) Then
RankBox2.Items.Add(test)
End If
Next
Next
Next
End If
If TextBox1.Text.Length > 2 Then
For Each c0 As Char In chars
For Each c1 As Char In chars
For Each c2 As Char In chars
For i As Integer = 0 To Rank3.Length - 1
test = Rank3(i)
If InStr(Rank3(i), c0 & c1 & c2) Then
RankBox3.Items.Add(test)
End If
Next
Next
Next
Next
End If
If TextBox1.Text.Length > 3 Then
For Each c0 As Char In chars
For Each c1 As Char In chars
For Each c2 As Char In chars
For Each c3 As Char In chars
For i As Integer = 0 To Rank4.Length - 1
test = Rank4(i)
If InStr(Rank4(i), c0 & c1 & c2 & c3) Then
RankBox4.Items.Add(test)
End If
Next
Next
Next
Next
Next
End If
If the goal is exclude the arrangement of characters that repeat themselves, then you would need to add a check before processing the code inside the for loops.
For example..
If TextBox1.Text.Length > 1 Then
For Each c0 As Char In chars
For Each c1 As Char In chars
If c0 <> c1 Then
For i As Integer = 0 To Rank2.Length - 1
test = Rank2(i)
If InStr(Rank2(i), c0 & c1) Then
RankBox2.Items.Add(test)
End If
Next
End If
Next
Next
End If
Same solution as #RyanRoos, but with indexes. So the compare is with the indexes.
Dim c0 As Char
Dim c1 As Char
If TextBox1.Text.Length > 1 Then
For i = 0 to chars.Length - 1
For j = 0 to chars.Length - 1
If i <> j Then
For k As Integer = 0 To Rank2.Length - 1
test = Rank2(k)
If InStr(Rank2(k), c0 & c1) Then
RankBox2.Items.Add(test)
End If
Next
End If
Next
Next
End If
So if you have ab, it will produce ab and ba
If you have aba, it will produce aab, aba, baa twice each, because the a at first pos has been permuted with a at third pos.

Serpent Sbox transformation

Consider I have this sample key
15FC0D48 D7F8199C BE399183 4D96F327 10000000 00000000 00000000 00000000
w-8 w-7 w-6 w-5 w-4 w-3 w-2 w-1
Creating first K0 Key Schedule pair
(k0,k1,k2,k3)=S3(w0,w1,w2,w3)=K0
using this formula for Serpent Key Schdule
wi=(wi-8 xor wi-5 xor wi-3 xor wi-1 xor phi xor i)<<<11
1) i=0
w0=w-8 xor w-5 xor w-3 xor w-1 xor 9e3779b9 xor 0<<<11=15FC0D48 xor 4D96F327 xor 00000000 xor 00000000 xor 9e3779b9 xor 0 <<<11=EC3EB632
2) i=1
w1=w-7 xor w-4 xor w-2 xor w0 xor 9e3779b9 xor 1<<<11=D7F8199C xor 10000000 xor 00000000 xor EC3EB632 xor 9e3779b9 xor 1<<<11=8EB0B5AF
3) i=2
w2=w-6 xor w-3 xor w-1 xor w1 xor 9e3779b9 xor 2<<<11=BE399183 xor 00000000 xor 00000000 xor 8EB0B5AF xor 9e3779b9 xor 2<<<11=F2ECBD75
4) i=3
w3=w-5 xor w-2 xor w0 xor w2 xor 9e3779b9 xor 3<<<11=4D96F327 xor 00000000 xor EC3EB632 xor F2ECBD75 xor 9e3779b9 xor 3<<<11=9C0ED66B
For k0 will be created by Sbox3
S3(w0,w1,w2,w3)
EC3EB632
binary form:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
11|10|11|00|00|11|11|10|10|11|01|10|00|11|00|10|
after Sbox3
11101010001111001110110001101100
EA3CEC6C
8EB0B5AF
binary form:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
10|00|11|10|10|11|00|00|10|11|01|01|10|10|11|11
after Sbox3
10110110101100101000111001001111
B6B28E4F
F2ECBD75
binary form:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
11|11|00|10|11|10|11|00|10|11|11|01|01|11|01|01
after Sbox3
11010110011111101111001111001001
D67EF3C9
9C0ED66B
binary form:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
10|01|11|00|00|00|11|10|11|01|01|10|01|10|10|11
after Sbox3
10111011010111001001110001100010
BB5C9C62
k0={EA3CEC6C B6B28E4F D67EF3C9 BB5C9C62}
I use my solution in C# for SBOX transformation:
String key="10011100000011101101011001101011";
prek="";
Uint32 k;
for (int i = sboxpos; i < sboxpos + 1; i++)
{
for (int i2 = 0; i2 < 16; i2++)
{
prek += key.Substring(sbox[i, i2] * 2, 2); //Multiplying on 2 to move byte on appropriate position, as in my example above I transform hex to binary it have 32bits, but Sbox'es moves only bytes. So e.g. the 15's byte is 15*2=30's position plus 2 characters
}
}
k = Convert.ToUInt32(prek, 2);
My question is am I doing Key schedule of Serpent right, as in other implementation they uses an &, operands in Sbox'es. Will I have same result by applying Sbox transformation in my code above? Thanks!