public static int[] NonZeroColumnPositions(Word[] w) { int[] konum = new int[0]; if (w.Length != 4) { throw new Exception("Word list size should be 4!"); } for (int i = 0; i < w[0].Size; i++) { Word t = Serpent.GetBitSlice(w, i); if (t.Contains('?') || t.Contains('1')) { Array.Resize(ref konum, konum.Length + 1); konum[konum.Length - 1] = i; } } return(konum); }
public static Word SerpentSBox(int round, Word input) { if (input.Contains('?')) return Word.Parse("????"); if (input.IsEqualTo("0000")) return Word.Parse("0000"); int SBoxID = round % 8; switch (SBoxID) { case 0: // Input: [02] 0010 -> Output: 1??? if (input.IsEqualTo("0010")) return Word.Parse("1???"); // Input: [04] 0100 -> Output: 1??? if (input.IsEqualTo("0100")) return Word.Parse("1???"); // Input: [06] 0110 -> Output: 0??? if (input.IsEqualTo("0110")) return Word.Parse("0???"); break; case 1: // Input: [04] 0100 -> Output: ?1?? if (input.IsEqualTo("0100")) return Word.Parse("?1??"); // Input: [08] 1000 -> Output: ?1?? if (input.IsEqualTo("1000")) return Word.Parse("?1??"); // Input: [0C] 1100 -> Output: ?0?? if (input.IsEqualTo("1100")) return Word.Parse("?0??"); break; case 2: // Input: [02] 0010 -> Output: ???1 if (input.IsEqualTo("0010")) return Word.Parse("???1"); // Input: [08] 1000 -> Output: ???1 if (input.IsEqualTo("1000")) return Word.Parse("???1"); // Input: [0A] 1010 -> Output: ???0 if (input.IsEqualTo("1010")) return Word.Parse("???0"); break; case 3: break; case 4: case 5: // Input: [04] 0100 -> Output: ???1 if (input.IsEqualTo("0100")) return Word.Parse("???1"); // Input: [0B] 1011 -> Output: ???1 if (input.IsEqualTo("1011")) return Word.Parse("???1"); // Input: [0F] 1111 -> Output: ???0 if (input.IsEqualTo("1111")) return Word.Parse("???0"); break; case 6: // Input: [02] 0010 -> Output: ??1? if (input.IsEqualTo("0010")) return Word.Parse("??1?"); // Input: [04] 0100 -> Output: ??1? if (input.IsEqualTo("0100")) return Word.Parse("??1?"); // Input: [06] 0110 -> Output: ??0? if (input.IsEqualTo("0110")) return Word.Parse("??0?"); break; case 7: break; } return Word.Parse("????"); }
public static Word SerpentSBox(int round, Word input) { if (input.Contains('?')) { return(Word.Parse("????")); } if (input.IsEqualTo("0000")) { return(Word.Parse("0000")); } int SBoxID = round % 8; switch (SBoxID) { case 0: // Input: [02] 0010 -> Output: 1??? if (input.IsEqualTo("0010")) { return(Word.Parse("1???")); } // Input: [04] 0100 -> Output: 1??? if (input.IsEqualTo("0100")) { return(Word.Parse("1???")); } // Input: [06] 0110 -> Output: 0??? if (input.IsEqualTo("0110")) { return(Word.Parse("0???")); } break; case 1: // Input: [04] 0100 -> Output: ?1?? if (input.IsEqualTo("0100")) { return(Word.Parse("?1??")); } // Input: [08] 1000 -> Output: ?1?? if (input.IsEqualTo("1000")) { return(Word.Parse("?1??")); } // Input: [0C] 1100 -> Output: ?0?? if (input.IsEqualTo("1100")) { return(Word.Parse("?0??")); } break; case 2: // Input: [02] 0010 -> Output: ???1 if (input.IsEqualTo("0010")) { return(Word.Parse("???1")); } // Input: [08] 1000 -> Output: ???1 if (input.IsEqualTo("1000")) { return(Word.Parse("???1")); } // Input: [0A] 1010 -> Output: ???0 if (input.IsEqualTo("1010")) { return(Word.Parse("???0")); } break; case 3: break; case 4: case 5: // Input: [04] 0100 -> Output: ???1 if (input.IsEqualTo("0100")) { return(Word.Parse("???1")); } // Input: [0B] 1011 -> Output: ???1 if (input.IsEqualTo("1011")) { return(Word.Parse("???1")); } // Input: [0F] 1111 -> Output: ???0 if (input.IsEqualTo("1111")) { return(Word.Parse("???0")); } break; case 6: // Input: [02] 0010 -> Output: ??1? if (input.IsEqualTo("0010")) { return(Word.Parse("??1?")); } // Input: [04] 0100 -> Output: ??1? if (input.IsEqualTo("0100")) { return(Word.Parse("??1?")); } // Input: [06] 0110 -> Output: ??0? if (input.IsEqualTo("0110")) { return(Word.Parse("??0?")); } break; case 7: break; } return(Word.Parse("????")); }