public void SinhKhoaCon(int MaHoaHayGiaiMa) // 1 la ma hoa -1 la giai ma { DayKhoaPhu = new ChuoiNhiPhan[16]; ChuoiNhiPhan ChuoiTrai, ChuoiPhai, MotKhoaPhu; // PC1 ChuoiNhiPhan[] ChuoiSauPC1 = CacThongSo.TinhPC1(KhoaChinhNhiPhan); ChuoiTrai = ChuoiSauPC1[0]; ChuoiPhai = ChuoiSauPC1[1]; for (int i = 0; i < 16; i++) { // Dich bit if (MaHoaHayGiaiMa == 1) // ma hoa { ChuoiTrai = ChuoiTrai.DichTraiBit(CacThongSo.soBitDichTaiCacVong[i]); ChuoiPhai = ChuoiPhai.DichTraiBit(CacThongSo.soBitDichTaiCacVong[i]); } else { ChuoiTrai = ChuoiTrai.DichPhaiBit(CacThongSo.soBitDichTaiCacVong[i]); ChuoiPhai = ChuoiPhai.DichPhaiBit(CacThongSo.soBitDichTaiCacVong[i]); } // PC2 MotKhoaPhu = CacThongSo.TinhPC2(ChuoiTrai, ChuoiPhai); if (MaHoaHayGiaiMa == 1) { DayKhoaPhu[i] = MotKhoaPhu; } else { DayKhoaPhu[15 - i] = MotKhoaPhu; } } }
public ChuoiNhiPhan ThucHienDES(ChuoiNhiPhan ChuoiVaoDai, int MaHoaHayGiaiMa)// 1 ma hoa, -1 giai ma { KhoaDES.SinhKhoaCon(MaHoaHayGiaiMa); ChuoiNhiPhan[] DSChuoiVao = ChuoiVaoDai.Chia(ChuoiVaoDai.DoDai / 64); ChuoiNhiPhan ChuoiVao, ChuoiKQ; ChuoiKQ = new ChuoiNhiPhan(0); for (int k = 0; k < DSChuoiVao.Length; k++) { ChuoiVao = DSChuoiVao[k]; ChuoiNhiPhan[] ChuoiSauIP; ChuoiNhiPhan ChuoiSauIP_1; ChuoiNhiPhan L, R, F, TG; ChuoiSauIP = CacThongSo.TinhIP(ChuoiVao, MaHoaHayGiaiMa); L = ChuoiSauIP[0]; R = ChuoiSauIP[1]; for (int i = 0; i < 16; i++) { F = HamF(R, KhoaDES.DayKhoaPhu[i]); L = L.XOR(F); TG = L; L = R; R = TG; } ChuoiSauIP_1 = CacThongSo.TinhIP_1(R, L, MaHoaHayGiaiMa); ChuoiKQ = ChuoiKQ.Cong(ChuoiSauIP_1); } return(ChuoiKQ); }
private ChuoiNhiPhan HamF(ChuoiNhiPhan chuoiVao, ChuoiNhiPhan KhoaCon) { ChuoiNhiPhan KQ = CacThongSo.TinhE(chuoiVao); KQ = KQ.XOR(KhoaCon); KQ = CacThongSo.TinhSBox(KQ); KQ = CacThongSo.TinhP(KQ); return(KQ); }
public void KhoiTaoMaTranMui() { MaTranMui = new double[BanDo.SoThanhPho, BanDo.SoThanhPho]; CacThongSo.KhoiTao(); for (int i = 0; i < BanDo.SoThanhPho; i++) { for (int j = 0; j < BanDo.SoThanhPho; j++) { MaTranMui[i, j] = CacThongSo.tMax; } } }