C#,河豚算法(Blowfish Algorithm)的加密、解密源代码

 Bruce Schneier

1 河豚算法(Blowfish Algorithm)

河豚算法(Blowfish Algorithm)是1993年11月由Bruce Schneier设计的一个完全开源的算法。

Blowfish算法是一个分组长度为64位、密钥长度可变的对称分组密码算法。
Blowfish算法具有加密速度快、紧凑、密钥长度可变、可免费使用等特点,已被广泛应用于众多加密软件。

Blowfish算法是一种对称的分组加密算法,算法核心在于子密钥生成,它将变长密钥扩展成总长4168 Byte的子密钥数组。算法中使用了大量的子密钥,而子密钥又依赖于用户密钥,实际加/解密过程中使用的是更新后的子密钥数组,子密钥即P数组和S盒。Blowfish算法有一个核心加密函数:BF_En(),该函数的输人是64位明文信息,经过运算,以64位密文信息的形式输出。用Blowfish算法加密信息,需要两个过程:密钥预处理和信息加密。同样,解密亦需要两个过程,密钥预处理和信息解密。
Blowfish算法的源密钥——pbox和sbox是固定的,而我们要加密一个信息,需要自己选择一个key,用这个key对pbox和sbox进行变换,得到下一步信息加密所要用的key_pbox和key_sbox。解密亦是如此,由于Blowfish是对称加密算法,解密方在得到key后根据key生成解密所需的key_box和key_sbox。对同一个信息加密解密,选取的key的不同会导致密文的不同。因此,Blowfish算法的关键在于key的选择以及保密。

由于Blowfish算法采用变长密钥,这在给用户带来极大便利的同时也有隐患。由于算法加/解密核心在于密钥的选择和保密,但在实际应用中经常使用一些弱密钥对信息资源进行加密,导致存在着很大的安全隐患。

2 文本格式源程序

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace Legalsoft.Truffer.Algorithm
{
    public static class Bowfish_Algorithm
    {
        private static string[,] Substitution_Boxes = new string[,] {
            { "d1310ba6", "98dfb5ac", "2ffd72db", "d01adfb7", "b8e1afed",
              "6a267e96", "ba7c9045", "f12c7f99", "24a19947", "b3916cf7",
              "0801f2e2", "858efc16", "636920d8", "71574e69", "a458fea3",
              "f4933d7e", "0d95748f", "728eb658", "718bcd58", "82154aee",
              "7b54a41d", "c25a59b5", "9c30d539", "2af26013", "c5d1b023",
              "286085f0", "ca417918", "b8db38ef", "8e79dcb0", "603a180e",
              "6c9e0e8b", "b01e8a3e", "d71577c1", "bd314b27", "78af2fda",
              "55605c60", "e65525f3", "aa55ab94", "57489862", "63e81440",
              "55ca396a", "2aab10b6", "b4cc5c34", "1141e8ce", "a15486af",
              "7c72e993", "b3ee1411", "636fbc2a", "2ba9c55d", "741831f6",
              "ce5c3e16", "9b87931e", "afd6ba33", "6c24cf5c", "7a325381",
              "28958677", "3b8f4898", "6b4bb9af", "c4bfe81b", "66282193",
              "61d809cc", "fb21a991", "487cac60", "5dec8032", "ef845d5d",
              "e98575b1", "dc262302", "eb651b88", "23893e81", "d396acc5",
              "0f6d6ff3", "83f44239", "2e0b4482", "a4842004", "69c8f04a",
              "9e1f9b5e", "21c66842", "f6e96c9a", "670c9c61", "abd388f0",
              "6a51a0d2", "d8542f68", "960fa728", "ab5133a3", "6eef0b6c",
              "137a3be4", "ba3bf050", "7efb2a98", "a1f1651d", "39af0176",
              "66ca593e", "82430e88", "8cee8619", "456f9fb4", "7d84a5c3",
              "3b8b5ebe", "e06f75d8", "85c12073", "401a449f", "56c16aa6",
              "4ed3aa62", "363f7706", "1bfedf72", "429b023d", "37d0d724",
              "d00a1248", "db0fead3", "49f1c09b", "075372c9", "80991b7b",
              "25d479d8", "f6e8def7", "e3fe501a", "b6794c3b", "976ce0bd",
              "04c006ba", "c1a94fb6", "409f60c4", "5e5c9ec2", "196a2463",
              "68fb6faf", "3e6c53b5", "1339b2eb", "3b52ec6f", "6dfc511f",
              "9b30952c", "cc814544", "af5ebd09", "bee3d004", "de334afd",
              "660f2807", "192e4bb3", "c0cba857", "45c8740f", "d20b5f39",
              "b9d3fbdb", "5579c0bd", "1a60320a", "d6a100c6", "402c7279",
              "679f25fe", "fb1fa3cc", "8ea5e9f8", "db3222f8", "3c7516df",
              "fd616b15", "2f501ec8", "ad0552ab", "323db5fa", "fd238760",
              "53317b48", "3e00df82", "9e5c57bb", "ca6f8ca0", "1a87562e",
              "df1769db", "d542a8f6", "287effc3", "ac6732c6", "8c4f5573",
              "695b27b0", "bbca58c8", "e1ffa35d", "b8f011a0", "10fa3d98",
              "fd2183b8", "4afcb56c", "2dd1d35b", "9a53e479", "b6f84565",
              "d28e49bc", "4bfb9790", "e1ddf2da", "a4cb7e33", "62fb1341",
              "cee4c6e8", "ef20cada", "36774c01", "d07e9efe", "2bf11fb4",
              "95dbda4d", "ae909198", "eaad8e71", "6b93d5a0", "d08ed1d0",
              "afc725e0", "8e3c5b2f", "8e7594b7", "8ff6e2fb", "f2122b64",
              "8888b812", "900df01c", "4fad5ea0", "688fc31c", "d1cff191",
              "b3a8c1ad", "2f2f2218", "be0e1777", "ea752dfe", "8b021fa1",
              "e5a0cc0f", "b56f74e8", "18acf3d6", "ce89e299", "b4a84fe0",
              "fd13e0b7", "7cc43b81", "d2ada8d9", "165fa266", "80957705",
              "93cc7314", "211a1477", "e6ad2065", "77b5fa86", "c75442f5",
              "fb9d35cf", "ebcdaf0c", "7b3e89a0", "d6411bd3", "ae1e7e49",
              "00250e2d", "2071b35e", "226800bb", "57b8e0af", "2464369b",
              "f009b91e", "5563911d", "59dfa6aa", "78c14389", "d95a537f",
              "207d5ba2", "02e5b9c5", "83260376", "6295cfa9", "11c81968",
              "4e734a41", "b3472dca", "7b14a94a", "1b510052", "9a532915",
              "d60f573f", "bc9bc6e4", "2b60a476", "81e67400", "08ba6fb5",
              "571be91f", "f296ec6b", "2a0dd915", "b6636521", "e7b9f9b6",
              "ff34052e", "c5855664", "53b02d5d", "a99f8fa1", "08ba4799",
              "6e85076a" },
            { "4b7a70e9", "b5b32944", "db75092e", "c4192623", "ad6ea6b0",
              "49a7df7d", "9cee60b8", "8fedb266", "ecaa8c71", "699a17ff",
              "5664526c", "c2b19ee1", "193602a5", "75094c29", "a0591340",
              "e4183a3e", "3f54989a", "5b429d65", "6b8fe4d6", "99f73fd6",
              "a1d29c07", "efe830f5", "4d2d38e6", "f0255dc1", "4cdd2086",
              "8470eb26", "6382e9c6", "021ecc5e", "09686b3f", "3ebaefc9",
              "3c971814", "6b6a70a1", "687f3584", "52a0e286", "b79c5305",
              "aa500737", "3e07841c", "7fdeae5c", "8e7d44ec", "5716f2b8",
              "b03ada37", "f0500c0d", "f01c1f04", "0200b3ff", "ae0cf51a",
              "3cb574b2", "25837a58", "dc0921bd", "d19113f9", "7ca92ff6",
              "94324773", "22f54701", "3ae5e581", "37c2dadc", "c8b57634",
              "9af3dda7", "a9446146", "0fd0030e", "ecc8c73e", "a4751e41",
              "e238cd99", "3bea0e2f", "3280bba1", "183eb331", "4e548b38",
              "4f6db908", "6f420d03", "f60a04bf", "2cb81290", "24977c79",
              "5679b072", "bcaf89af", "de9a771f", "d9930810", "b38bae12",
              "dccf3f2e", "5512721f", "2e6b7124", "501adde6", "9f84cd87",
              "7a584718", "7408da17", "bc9f9abc", "e94b7d8c", "ec7aec3a",
              "db851dfa", "63094366", "c464c3d2", "ef1c1847", "3215d908",
              "dd433b37", "24c2ba16", "12a14d43", "2a65c451", "50940002",
              "133ae4dd", "71dff89e", "10314e55", "81ac77d6", "5f11199b",
              "043556f1", "d7a3c76b", "3c11183b", "5924a509", "f28fe6ed",
              "97f1fbfa", "9ebabf2c", "1e153c6e", "86e34570", "eae96fb1",
              "860e5e0a", "5a3e2ab3", "771fe71c", "4e3d06fa", "2965dcb9",
              "99e71d0f", "803e89d6", "5266c825", "2e4cc978", "9c10b36a",
              "c6150eba", "94e2ea78", "a5fc3c53", "1e0a2df4", "f2f74ea7",
              "361d2b3d", "1939260f", "19c27960", "5223a708", "f71312b6",
              "ebadfe6e", "eac31f66", "e3bc4595", "a67bc883", "b17f37d1",
              "018cff28", "c332ddef", "be6c5aa5", "65582185", "68ab9802",
              "eecea50f", "db2f953b", "2aef7dad", "5b6e2f84", "1521b628",
              "29076170", "ecdd4775", "619f1510", "13cca830", "eb61bd96",
              "0334fe1e", "aa0363cf", "b5735c90", "4c70a239", "d59e9e0b",
              "cbaade14", "eecc86bc", "60622ca7", "9cab5cab", "b2f3846e",
              "648b1eaf", "19bdf0ca", "a02369b9", "655abb50", "40685a32",
              "3c2ab4b3", "319ee9d5", "c021b8f7", "9b540b19", "875fa099",
              "95f7997e", "623d7da8", "f837889a", "97e32d77", "11ed935f",
              "16681281", "0e358829", "c7e61fd6", "96dedfa1", "7858ba99",
              "57f584a5", "1b227263", "9b83c3ff", "1ac24696", "cdb30aeb",
              "532e3054", "8fd948e4", "6dbc3128", "58ebf2ef", "34c6ffea",
              "fe28ed61", "ee7c3c73", "5d4a14d9", "e864b7e3", "42105d14",
              "203e13e0", "45eee2b6", "a3aaabea", "db6c4f15", "facb4fd0",
              "c742f442", "ef6abbb5", "654f3b1d", "41cd2105", "d81e799e",
              "86854dc7", "e44b476a", "3d816250", "cf62a1f2", "5b8d2646",
              "fc8883a0", "c1c7b6a3", "7f1524c3", "69cb7492", "47848a0b",
              "5692b285", "095bbf00", "ad19489d", "1462b174", "23820e00",
              "58428d2a", "0c55f5ea", "1dadf43e", "233f7061", "3372f092",
              "8d937e41", "d65fecf1", "6c223bdb", "7cde3759", "cbee7460",
              "4085f2a7", "ce77326e", "a6078084", "19f8509e", "e8efd855",
              "61d99735", "a969a7aa", "c50c06c2", "5a04abfc", "800bcadc",
              "9e447a2e", "c3453484", "fdd56705", "0e1e9ec9", "db73dbd3",
              "105588cd", "675fda79", "e3674340", "c5c43465", "713e38d8",
              "3d28f89e", "f16dff20", "153e21e7", "8fb03d4a", "e6e39f2b",
              "db83adf7" },
            { "e93d5a68", "948140f7", "f64c261c", "94692934", "411520f7",
              "7602d4f7", "bcf46b2e", "d4a20068", "d4082471", "3320f46a",
              "43b7d4b7", "500061af", "1e39f62e", "97244546", "14214f74",
              "bf8b8840", "4d95fc1d", "96b591af", "70f4ddd3", "66a02f45",
              "bfbc09ec", "03bd9785", "7fac6dd0", "31cb8504", "96eb27b3",
              "55fd3941", "da2547e6", "abca0a9a", "28507825", "530429f4",
              "0a2c86da", "e9b66dfb", "68dc1462", "d7486900", "680ec0a4",
              "27a18dee", "4f3ffea2", "e887ad8c", "b58ce006", "7af4d6b6",
              "aace1e7c", "d3375fec", "ce78a399", "406b2a42", "20fe9e35",
              "d9f385b9", "ee39d7ab", "3b124e8b", "1dc9faf7", "4b6d1856",
              "26a36631", "eae397b2", "3a6efa74", "dd5b4332", "6841e7f7",
              "ca7820fb", "fb0af54e", "d8feb397", "454056ac", "ba489527",
              "55533a3a", "20838d87", "fe6ba9b7", "d096954b", "55a867bc",
              "a1159a58", "cca92963", "99e1db33", "a62a4a56", "3f3125f9",
              "5ef47e1c", "9029317c", "fdf8e802", "04272f70", "80bb155c",
              "05282ce3", "95c11548", "e4c66d22", "48c1133f", "c70f86dc",
              "07f9c9ee", "41041f0f", "404779a4", "5d886e17", "325f51eb",
              "d59bc0d1", "f2bcc18f", "41113564", "257b7834", "602a9c60",
              "dff8e8a3", "1f636c1b", "0e12b4c2", "02e1329e", "af664fd1",
              "cad18115", "6b2395e0", "333e92e1", "3b240b62", "eebeb922",
              "85b2a20e", "e6ba0d99", "de720c8c", "2da2f728", "d0127845",
              "95b794fd", "647d0862", "e7ccf5f0", "5449a36f", "877d48fa",
              "c39dfd27", "f33e8d1e", "0a476341", "992eff74", "3a6f6eab",
              "f4f8fd37", "a812dc60", "a1ebddf8", "991be14c", "db6e6b0d",
              "c67b5510", "6d672c37", "2765d43b", "dcd0e804", "f1290dc7",
              "cc00ffa3", "b5390f92", "690fed0b", "667b9ffb", "cedb7d9c",
              "a091cf0b", "d9155ea3", "bb132f88", "515bad24", "7b9479bf",
              "763bd6eb", "37392eb3", "cc115979", "8026e297", "f42e312d",
              "6842ada7", "c66a2b3b", "12754ccc", "782ef11c", "6a124237",
              "b79251e7", "06a1bbe6", "4bfb6350", "1a6b1018", "11caedfa",
              "3d25bdd8", "e2e1c3c9", "44421659", "0a121386", "d90cec6e",
              "d5abea2a", "64af674e", "da86a85f", "bebfe988", "64e4c3fe",
              "9dbc8057", "f0f7c086", "60787bf8", "6003604d", "d1fd8346",
              "f6381fb0", "7745ae04", "d736fccc", "83426b33", "f01eab71",
              "b0804187", "3c005e5f", "77a057be", "bde8ae24", "55464299",
              "bf582e61", "4e58f48f", "f2ddfda2", "f474ef38", "8789bdc2",
              "5366f9c3", "c8b38e74", "b475f255", "46fcd9b9", "7aeb2661",
              "8b1ddf84", "846a0e79", "915f95e2", "466e598e", "20b45770",
              "8cd55591", "c902de4c", "b90bace1", "bb8205d0", "11a86248",
              "7574a99e", "b77f19b6", "e0a9dc09", "662d09a1", "c4324633",
              "e85a1f02", "09f0be8c", "4a99a025", "1d6efe10", "1ab93d1d",
              "0ba5a4df", "a186f20f", "2868f169", "dcb7da83", "573906fe",
              "a1e2ce9b", "4fcd7f52", "50115e01", "a70683fa", "a002b5c4",
              "0de6d027", "9af88c27", "773f8641", "c3604c06", "61a806b5",
              "f0177a28", "c0f586e0", "006058aa", "30dc7d62", "11e69ed7",
              "2338ea63", "53c2dd94", "c2c21634", "bbcbee56", "90bcb6de",
              "ebfc7da1", "ce591d76", "6f05e409", "4b7c0188", "39720a3d",
              "7c927c24", "86e3725f", "724d9db9", "1ac15bb4", "d39eb8fc",
              "ed545578", "08fca5b5", "d83d7cd3", "4dad0fc4", "1e50ef5e",
              "b161e6f8", "a28514d9", "6c51133c", "6fd5c7e7", "56e14ec4",
              "362abfce", "ddc6c837", "d79a3234", "92638212", "670efa8e",
              "406000e0" },
            { "3a39ce37", "d3faf5cf", "abc27737", "5ac52d1b", "5cb0679e",
              "4fa33742", "d3822740", "99bc9bbe", "d5118e9d", "bf0f7315",
              "d62d1c7e", "c700c47b", "b78c1b6b", "21a19045", "b26eb1be",
              "6a366eb4", "5748ab2f", "bc946e79", "c6a376d2", "6549c2c8",
              "530ff8ee", "468dde7d", "d5730a1d", "4cd04dc6", "2939bbdb",
              "a9ba4650", "ac9526e8", "be5ee304", "a1fad5f0", "6a2d519a",
              "63ef8ce2", "9a86ee22", "c089c2b8", "43242ef6", "a51e03aa",
              "9cf2d0a4", "83c061ba", "9be96a4d", "8fe51550", "ba645bd6",
              "2826a2f9", "a73a3ae1", "4ba99586", "ef5562e9", "c72fefd3",
              "f752f7da", "3f046f69", "77fa0a59", "80e4a915", "87b08601",
              "9b09e6ad", "3b3ee593", "e990fd5a", "9e34d797", "2cf0b7d9",
              "022b8b51", "96d5ac3a", "017da67d", "d1cf3ed6", "7c7d2d28",
              "1f9f25cf", "adf2b89b", "5ad6b472", "5a88f54c", "e029ac71",
              "e019a5e6", "47b0acfd", "ed93fa9b", "e8d3c48d", "283b57cc",
              "f8d56629", "79132e28", "785f0191", "ed756055", "f7960e44",
              "e3d35e8c", "15056dd4", "88f46dba", "03a16125", "0564f0bd",
              "c3eb9e15", "3c9057a2", "97271aec", "a93a072a", "1b3f6d9b",
              "1e6321f5", "f59c66fb", "26dcf319", "7533d928", "b155fdf5",
              "03563482", "8aba3cbb", "28517711", "c20ad9f8", "abcc5167",
              "ccad925f", "4de81751", "3830dc8e", "379d5862", "9320f991",
              "ea7a90c2", "fb3e7bce", "5121ce64", "774fbe32", "a8b6e37e",
              "c3293d46", "48de5369", "6413e680", "a2ae0810", "dd6db224",
              "69852dfd", "09072166", "b39a460a", "6445c0dd", "586cdecf",
              "1c20c8ae", "5bbef7dd", "1b588d40", "ccd2017f", "6bb4e3bb",
              "dda26a7e", "3a59ff45", "3e350a44", "bcb4cdd5", "72eacea8",
              "fa6484bb", "8d6612ae", "bf3c6f47", "d29be463", "542f5d9e",
              "aec2771b", "f64e6370", "740e0d8d", "e75b1357", "f8721671",
              "af537d5d", "4040cb08", "4eb4e2cc", "34d2466a", "0115af84",
              "e1b00428", "95983a1d", "06b89fb4", "ce6ea048", "6f3f3b82",
              "3520ab82", "011a1d4b", "277227f8", "611560b1", "e7933fdc",
              "bb3a792b", "344525bd", "a08839e1", "51ce794b", "2f32c9b7",
              "a01fbac9", "e01cc87e", "bcc7d1f6", "cf0111c3", "a1e8aac7",
              "1a908749", "d44fbd9a", "d0dadecb", "d50ada38", "0339c32a",
              "c6913667", "8df9317c", "e0b12b4f", "f79e59b7", "43f5bb3a",
              "f2d519ff", "27d9459c", "bf97222c", "15e6fc2a", "0f91fc71",
              "9b941525", "fae59361", "ceb69ceb", "c2a86459", "12baa8d1",
              "b6c1075e", "e3056a0c", "10d25065", "cb03a442", "e0ec6e0e",
              "1698db3b", "4c98a0be", "3278e964", "9f1f9532", "e0d392df",
              "d3a0342b", "8971f21e", "1b0a7441", "4ba3348c", "c5be7120",
              "c37632d8", "df359f8d", "9b992f2e", "e60b6f47", "0fe3f11d",
              "e54cda54", "1edad891", "ce6279cf", "cd3e7e6f", "1618b166",
              "fd2c1d05", "848fd2c5", "f6fb2299", "f523f357", "a6327623",
              "93a83531", "56cccd02", "acf08162", "5a75ebb5", "6e163697",
              "88d273cc", "de966292", "81b949d0", "4c50901b", "71c65614",
              "e6c6c7bd", "327a140a", "45e1d006", "c3f27b9a", "c9aa53fd",
              "62a80f00", "bb25bfe2", "35bdd2f6", "71126905", "b2040222",
              "b6cbcf7c", "cd769c2b", "53113ec0", "1640e3d3", "38abbd60",
              "2547adf0", "ba38209c", "f746ce76", "77afa1c5", "20756060",
              "85cbfe4e", "8ae88dd8", "7aaaf9b0", "4cf9aa7e", "1948c25c",
              "02fb8a8c", "01c36ae4", "d6ebe1f9", "90d4f869", "a65cdea0",
              "3f09252d", "c208e69f", "b74e6132", "ce77e25b", "578fdfe3",
              "3ac372e6" }
        };

        private static string[] Pi_Subkeys = new string[] {
            "243f6a88", "85a308d3", "13198a2e", "03707344", "a4093822",
            "299f31d0", "082efa98", "ec4e6c89", "452821e6", "38d01377",
            "be5466cf", "34e90c6c", "c0ac29b7", "c97c50dd", "3f84d5b5",
            "b5470917", "9216d5d9", "8979fb1b"
        };

        private static long modVal = 1;
        
        private static string HexadecimalToBinary(string plainText)
        {
            string binary = "";
            int n = plainText.Length;
            for (int i = 0; i < n; i++)
            {
                int num = Convert.ToInt32(plainText[i] + "", 16);
                string binary4B = Convert.ToString(num, 2);
                binary4B = "0000" + binary4B;
                binary4B = binary4B.Substring(binary4B.Length - 4);
                binary += binary4B;
            }
            return binary;
        }


        private static string BinaryToHexadecimal(string plainText)
        {
            int num = Convert.ToInt32(plainText, 2);
            string hexa = num.ToString("x");
            while (hexa.Length < (plainText.Length / 4))
            {
                hexa = "0" + hexa;
            }
            return hexa;
        }

        private static string HexadecimalXor(string a, string b)
        {
            a = HexadecimalToBinary(a);
            b = HexadecimalToBinary(b);
            string ans = "";
            for (int i = 0; i < a.Length; i++)
            {
                ans += (char)(((a[i] - '0') ^ (b[i] - '0')) + '0');
            }
            ans = BinaryToHexadecimal(ans);
            return ans;
        }

        private static string AddBinaryModula(string a, string b)
        {
            int n1 = Convert.ToInt32(a, 16);
            int n2 = Convert.ToInt32(b, 16);
            n1 = (int)((n1 + n2) % modVal);
            string ans = n1.ToString("x");
            ans = "00000000" + ans;
            return ans.Substring(ans.Length - 8);
        }

        private static string Function(string plainText)
        {
            string[] a = new string[4];
            for (int i = 0; i < 8; i += 2)
            {
                int col = Convert.ToInt32(HexadecimalToBinary(plainText.Substring(i, 2)), 2);
                a[i / 2] = Substitution_Boxes[i / 2, (int)col];
            }
            string ans = AddBinaryModula(a[0], a[1]);
            ans = HexadecimalXor(ans, a[2]);
            ans = AddBinaryModula(ans, a[3]);
            return ans;
        }

        private static void KeyGenerate(string key)
        {
            int j = 0;
            for (int i = 0; i < Pi_Subkeys.Length; i++)
            {
                Pi_Subkeys[i] = HexadecimalXor(Pi_Subkeys[i], key.Substring(j, 8));
                j = (j + 8) % key.Length;
            }
        }

        private static string Round(int time, string plainText)
        {
            string left, right;
            left = plainText.Substring(0, 8);
            right = plainText.Substring(8, 16 - 8);
            left = HexadecimalXor(left, Pi_Subkeys[time]);
            string fOut = Function(left);
            right = HexadecimalXor(fOut, right);
            return right + left;
        }

        public static string Encrypt(string plainText, string key = "01234567ABCDEF00")
        {
            if (modVal == 1)
            {
                for (int i = 0; i < 32; i++)
                {
                    modVal = modVal << 1;
                }
                KeyGenerate(key);
            }
            for (int i = 0; i < 16; i++)
            {
                plainText = Round(i, plainText);
            }
            string right = plainText.Substring(0, 8);
            string left = plainText.Substring(8, 16 - 8);
            right = HexadecimalXor(right, Pi_Subkeys[16]);
            left = HexadecimalXor(left, Pi_Subkeys[17]);
            return left + right;
        }

        public static string Decrypt(string plainText, string key = "01234567ABCDEF00")
        {
            if (modVal == 1)
            {
                for (int i = 0; i < 32; i++)
                {
                    modVal = modVal << 1;
                }
                KeyGenerate(key);
            }
            for (int i = 17; i > 1; i--)
            {
                plainText = Round(i, plainText);
            }
            string right = plainText.Substring(0, 8);
            string left = plainText.Substring(8, 16 - 8);
            right = HexadecimalXor(right, Pi_Subkeys[1]);
            left = HexadecimalXor(left, Pi_Subkeys[0]);
            return left + right;
        }

    }
}
 

3 代码格式

using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;namespace Legalsoft.Truffer.Algorithm
{public static class Bowfish_Algorithm{private static string[,] Substitution_Boxes = new string[,] {{ "d1310ba6", "98dfb5ac", "2ffd72db", "d01adfb7", "b8e1afed","6a267e96", "ba7c9045", "f12c7f99", "24a19947", "b3916cf7","0801f2e2", "858efc16", "636920d8", "71574e69", "a458fea3","f4933d7e", "0d95748f", "728eb658", "718bcd58", "82154aee","7b54a41d", "c25a59b5", "9c30d539", "2af26013", "c5d1b023","286085f0", "ca417918", "b8db38ef", "8e79dcb0", "603a180e","6c9e0e8b", "b01e8a3e", "d71577c1", "bd314b27", "78af2fda","55605c60", "e65525f3", "aa55ab94", "57489862", "63e81440","55ca396a", "2aab10b6", "b4cc5c34", "1141e8ce", "a15486af","7c72e993", "b3ee1411", "636fbc2a", "2ba9c55d", "741831f6","ce5c3e16", "9b87931e", "afd6ba33", "6c24cf5c", "7a325381","28958677", "3b8f4898", "6b4bb9af", "c4bfe81b", "66282193","61d809cc", "fb21a991", "487cac60", "5dec8032", "ef845d5d","e98575b1", "dc262302", "eb651b88", "23893e81", "d396acc5","0f6d6ff3", "83f44239", "2e0b4482", "a4842004", "69c8f04a","9e1f9b5e", "21c66842", "f6e96c9a", "670c9c61", "abd388f0","6a51a0d2", "d8542f68", "960fa728", "ab5133a3", "6eef0b6c","137a3be4", "ba3bf050", "7efb2a98", "a1f1651d", "39af0176","66ca593e", "82430e88", "8cee8619", "456f9fb4", "7d84a5c3","3b8b5ebe", "e06f75d8", "85c12073", "401a449f", "56c16aa6","4ed3aa62", "363f7706", "1bfedf72", "429b023d", "37d0d724","d00a1248", "db0fead3", "49f1c09b", "075372c9", "80991b7b","25d479d8", "f6e8def7", "e3fe501a", "b6794c3b", "976ce0bd","04c006ba", "c1a94fb6", "409f60c4", "5e5c9ec2", "196a2463","68fb6faf", "3e6c53b5", "1339b2eb", "3b52ec6f", "6dfc511f","9b30952c", "cc814544", "af5ebd09", "bee3d004", "de334afd","660f2807", "192e4bb3", "c0cba857", "45c8740f", "d20b5f39","b9d3fbdb", "5579c0bd", "1a60320a", "d6a100c6", "402c7279","679f25fe", "fb1fa3cc", "8ea5e9f8", "db3222f8", "3c7516df","fd616b15", "2f501ec8", "ad0552ab", "323db5fa", "fd238760","53317b48", "3e00df82", "9e5c57bb", "ca6f8ca0", "1a87562e","df1769db", "d542a8f6", "287effc3", "ac6732c6", "8c4f5573","695b27b0", "bbca58c8", "e1ffa35d", "b8f011a0", "10fa3d98","fd2183b8", "4afcb56c", "2dd1d35b", "9a53e479", "b6f84565","d28e49bc", "4bfb9790", "e1ddf2da", "a4cb7e33", "62fb1341","cee4c6e8", "ef20cada", "36774c01", "d07e9efe", "2bf11fb4","95dbda4d", "ae909198", "eaad8e71", "6b93d5a0", "d08ed1d0","afc725e0", "8e3c5b2f", "8e7594b7", "8ff6e2fb", "f2122b64","8888b812", "900df01c", "4fad5ea0", "688fc31c", "d1cff191","b3a8c1ad", "2f2f2218", "be0e1777", "ea752dfe", "8b021fa1","e5a0cc0f", "b56f74e8", "18acf3d6", "ce89e299", "b4a84fe0","fd13e0b7", "7cc43b81", "d2ada8d9", "165fa266", "80957705","93cc7314", "211a1477", "e6ad2065", "77b5fa86", "c75442f5","fb9d35cf", "ebcdaf0c", "7b3e89a0", "d6411bd3", "ae1e7e49","00250e2d", "2071b35e", "226800bb", "57b8e0af", "2464369b","f009b91e", "5563911d", "59dfa6aa", "78c14389", "d95a537f","207d5ba2", "02e5b9c5", "83260376", "6295cfa9", "11c81968","4e734a41", "b3472dca", "7b14a94a", "1b510052", "9a532915","d60f573f", "bc9bc6e4", "2b60a476", "81e67400", "08ba6fb5","571be91f", "f296ec6b", "2a0dd915", "b6636521", "e7b9f9b6","ff34052e", "c5855664", "53b02d5d", "a99f8fa1", "08ba4799","6e85076a" },{ "4b7a70e9", "b5b32944", "db75092e", "c4192623", "ad6ea6b0","49a7df7d", "9cee60b8", "8fedb266", "ecaa8c71", "699a17ff","5664526c", "c2b19ee1", "193602a5", "75094c29", "a0591340","e4183a3e", "3f54989a", "5b429d65", "6b8fe4d6", "99f73fd6","a1d29c07", "efe830f5", "4d2d38e6", "f0255dc1", "4cdd2086","8470eb26", "6382e9c6", "021ecc5e", "09686b3f", "3ebaefc9","3c971814", "6b6a70a1", "687f3584", "52a0e286", "b79c5305","aa500737", "3e07841c", "7fdeae5c", "8e7d44ec", "5716f2b8","b03ada37", "f0500c0d", "f01c1f04", "0200b3ff", "ae0cf51a","3cb574b2", "25837a58", "dc0921bd", "d19113f9", "7ca92ff6","94324773", "22f54701", "3ae5e581", "37c2dadc", "c8b57634","9af3dda7", "a9446146", "0fd0030e", "ecc8c73e", "a4751e41","e238cd99", "3bea0e2f", "3280bba1", "183eb331", "4e548b38","4f6db908", "6f420d03", "f60a04bf", "2cb81290", "24977c79","5679b072", "bcaf89af", "de9a771f", "d9930810", "b38bae12","dccf3f2e", "5512721f", "2e6b7124", "501adde6", "9f84cd87","7a584718", "7408da17", "bc9f9abc", "e94b7d8c", "ec7aec3a","db851dfa", "63094366", "c464c3d2", "ef1c1847", "3215d908","dd433b37", "24c2ba16", "12a14d43", "2a65c451", "50940002","133ae4dd", "71dff89e", "10314e55", "81ac77d6", "5f11199b","043556f1", "d7a3c76b", "3c11183b", "5924a509", "f28fe6ed","97f1fbfa", "9ebabf2c", "1e153c6e", "86e34570", "eae96fb1","860e5e0a", "5a3e2ab3", "771fe71c", "4e3d06fa", "2965dcb9","99e71d0f", "803e89d6", "5266c825", "2e4cc978", "9c10b36a","c6150eba", "94e2ea78", "a5fc3c53", "1e0a2df4", "f2f74ea7","361d2b3d", "1939260f", "19c27960", "5223a708", "f71312b6","ebadfe6e", "eac31f66", "e3bc4595", "a67bc883", "b17f37d1","018cff28", "c332ddef", "be6c5aa5", "65582185", "68ab9802","eecea50f", "db2f953b", "2aef7dad", "5b6e2f84", "1521b628","29076170", "ecdd4775", "619f1510", "13cca830", "eb61bd96","0334fe1e", "aa0363cf", "b5735c90", "4c70a239", "d59e9e0b","cbaade14", "eecc86bc", "60622ca7", "9cab5cab", "b2f3846e","648b1eaf", "19bdf0ca", "a02369b9", "655abb50", "40685a32","3c2ab4b3", "319ee9d5", "c021b8f7", "9b540b19", "875fa099","95f7997e", "623d7da8", "f837889a", "97e32d77", "11ed935f","16681281", "0e358829", "c7e61fd6", "96dedfa1", "7858ba99","57f584a5", "1b227263", "9b83c3ff", "1ac24696", "cdb30aeb","532e3054", "8fd948e4", "6dbc3128", "58ebf2ef", "34c6ffea","fe28ed61", "ee7c3c73", "5d4a14d9", "e864b7e3", "42105d14","203e13e0", "45eee2b6", "a3aaabea", "db6c4f15", "facb4fd0","c742f442", "ef6abbb5", "654f3b1d", "41cd2105", "d81e799e","86854dc7", "e44b476a", "3d816250", "cf62a1f2", "5b8d2646","fc8883a0", "c1c7b6a3", "7f1524c3", "69cb7492", "47848a0b","5692b285", "095bbf00", "ad19489d", "1462b174", "23820e00","58428d2a", "0c55f5ea", "1dadf43e", "233f7061", "3372f092","8d937e41", "d65fecf1", "6c223bdb", "7cde3759", "cbee7460","4085f2a7", "ce77326e", "a6078084", "19f8509e", "e8efd855","61d99735", "a969a7aa", "c50c06c2", "5a04abfc", "800bcadc","9e447a2e", "c3453484", "fdd56705", "0e1e9ec9", "db73dbd3","105588cd", "675fda79", "e3674340", "c5c43465", "713e38d8","3d28f89e", "f16dff20", "153e21e7", "8fb03d4a", "e6e39f2b","db83adf7" },{ "e93d5a68", "948140f7", "f64c261c", "94692934", "411520f7","7602d4f7", "bcf46b2e", "d4a20068", "d4082471", "3320f46a","43b7d4b7", "500061af", "1e39f62e", "97244546", "14214f74","bf8b8840", "4d95fc1d", "96b591af", "70f4ddd3", "66a02f45","bfbc09ec", "03bd9785", "7fac6dd0", "31cb8504", "96eb27b3","55fd3941", "da2547e6", "abca0a9a", "28507825", "530429f4","0a2c86da", "e9b66dfb", "68dc1462", "d7486900", "680ec0a4","27a18dee", "4f3ffea2", "e887ad8c", "b58ce006", "7af4d6b6","aace1e7c", "d3375fec", "ce78a399", "406b2a42", "20fe9e35","d9f385b9", "ee39d7ab", "3b124e8b", "1dc9faf7", "4b6d1856","26a36631", "eae397b2", "3a6efa74", "dd5b4332", "6841e7f7","ca7820fb", "fb0af54e", "d8feb397", "454056ac", "ba489527","55533a3a", "20838d87", "fe6ba9b7", "d096954b", "55a867bc","a1159a58", "cca92963", "99e1db33", "a62a4a56", "3f3125f9","5ef47e1c", "9029317c", "fdf8e802", "04272f70", "80bb155c","05282ce3", "95c11548", "e4c66d22", "48c1133f", "c70f86dc","07f9c9ee", "41041f0f", "404779a4", "5d886e17", "325f51eb","d59bc0d1", "f2bcc18f", "41113564", "257b7834", "602a9c60","dff8e8a3", "1f636c1b", "0e12b4c2", "02e1329e", "af664fd1","cad18115", "6b2395e0", "333e92e1", "3b240b62", "eebeb922","85b2a20e", "e6ba0d99", "de720c8c", "2da2f728", "d0127845","95b794fd", "647d0862", "e7ccf5f0", "5449a36f", "877d48fa","c39dfd27", "f33e8d1e", "0a476341", "992eff74", "3a6f6eab","f4f8fd37", "a812dc60", "a1ebddf8", "991be14c", "db6e6b0d","c67b5510", "6d672c37", "2765d43b", "dcd0e804", "f1290dc7","cc00ffa3", "b5390f92", "690fed0b", "667b9ffb", "cedb7d9c","a091cf0b", "d9155ea3", "bb132f88", "515bad24", "7b9479bf","763bd6eb", "37392eb3", "cc115979", "8026e297", "f42e312d","6842ada7", "c66a2b3b", "12754ccc", "782ef11c", "6a124237","b79251e7", "06a1bbe6", "4bfb6350", "1a6b1018", "11caedfa","3d25bdd8", "e2e1c3c9", "44421659", "0a121386", "d90cec6e","d5abea2a", "64af674e", "da86a85f", "bebfe988", "64e4c3fe","9dbc8057", "f0f7c086", "60787bf8", "6003604d", "d1fd8346","f6381fb0", "7745ae04", "d736fccc", "83426b33", "f01eab71","b0804187", "3c005e5f", "77a057be", "bde8ae24", "55464299","bf582e61", "4e58f48f", "f2ddfda2", "f474ef38", "8789bdc2","5366f9c3", "c8b38e74", "b475f255", "46fcd9b9", "7aeb2661","8b1ddf84", "846a0e79", "915f95e2", "466e598e", "20b45770","8cd55591", "c902de4c", "b90bace1", "bb8205d0", "11a86248","7574a99e", "b77f19b6", "e0a9dc09", "662d09a1", "c4324633","e85a1f02", "09f0be8c", "4a99a025", "1d6efe10", "1ab93d1d","0ba5a4df", "a186f20f", "2868f169", "dcb7da83", "573906fe","a1e2ce9b", "4fcd7f52", "50115e01", "a70683fa", "a002b5c4","0de6d027", "9af88c27", "773f8641", "c3604c06", "61a806b5","f0177a28", "c0f586e0", "006058aa", "30dc7d62", "11e69ed7","2338ea63", "53c2dd94", "c2c21634", "bbcbee56", "90bcb6de","ebfc7da1", "ce591d76", "6f05e409", "4b7c0188", "39720a3d","7c927c24", "86e3725f", "724d9db9", "1ac15bb4", "d39eb8fc","ed545578", "08fca5b5", "d83d7cd3", "4dad0fc4", "1e50ef5e","b161e6f8", "a28514d9", "6c51133c", "6fd5c7e7", "56e14ec4","362abfce", "ddc6c837", "d79a3234", "92638212", "670efa8e","406000e0" },{ "3a39ce37", "d3faf5cf", "abc27737", "5ac52d1b", "5cb0679e","4fa33742", "d3822740", "99bc9bbe", "d5118e9d", "bf0f7315","d62d1c7e", "c700c47b", "b78c1b6b", "21a19045", "b26eb1be","6a366eb4", "5748ab2f", "bc946e79", "c6a376d2", "6549c2c8","530ff8ee", "468dde7d", "d5730a1d", "4cd04dc6", "2939bbdb","a9ba4650", "ac9526e8", "be5ee304", "a1fad5f0", "6a2d519a","63ef8ce2", "9a86ee22", "c089c2b8", "43242ef6", "a51e03aa","9cf2d0a4", "83c061ba", "9be96a4d", "8fe51550", "ba645bd6","2826a2f9", "a73a3ae1", "4ba99586", "ef5562e9", "c72fefd3","f752f7da", "3f046f69", "77fa0a59", "80e4a915", "87b08601","9b09e6ad", "3b3ee593", "e990fd5a", "9e34d797", "2cf0b7d9","022b8b51", "96d5ac3a", "017da67d", "d1cf3ed6", "7c7d2d28","1f9f25cf", "adf2b89b", "5ad6b472", "5a88f54c", "e029ac71","e019a5e6", "47b0acfd", "ed93fa9b", "e8d3c48d", "283b57cc","f8d56629", "79132e28", "785f0191", "ed756055", "f7960e44","e3d35e8c", "15056dd4", "88f46dba", "03a16125", "0564f0bd","c3eb9e15", "3c9057a2", "97271aec", "a93a072a", "1b3f6d9b","1e6321f5", "f59c66fb", "26dcf319", "7533d928", "b155fdf5","03563482", "8aba3cbb", "28517711", "c20ad9f8", "abcc5167","ccad925f", "4de81751", "3830dc8e", "379d5862", "9320f991","ea7a90c2", "fb3e7bce", "5121ce64", "774fbe32", "a8b6e37e","c3293d46", "48de5369", "6413e680", "a2ae0810", "dd6db224","69852dfd", "09072166", "b39a460a", "6445c0dd", "586cdecf","1c20c8ae", "5bbef7dd", "1b588d40", "ccd2017f", "6bb4e3bb","dda26a7e", "3a59ff45", "3e350a44", "bcb4cdd5", "72eacea8","fa6484bb", "8d6612ae", "bf3c6f47", "d29be463", "542f5d9e","aec2771b", "f64e6370", "740e0d8d", "e75b1357", "f8721671","af537d5d", "4040cb08", "4eb4e2cc", "34d2466a", "0115af84","e1b00428", "95983a1d", "06b89fb4", "ce6ea048", "6f3f3b82","3520ab82", "011a1d4b", "277227f8", "611560b1", "e7933fdc","bb3a792b", "344525bd", "a08839e1", "51ce794b", "2f32c9b7","a01fbac9", "e01cc87e", "bcc7d1f6", "cf0111c3", "a1e8aac7","1a908749", "d44fbd9a", "d0dadecb", "d50ada38", "0339c32a","c6913667", "8df9317c", "e0b12b4f", "f79e59b7", "43f5bb3a","f2d519ff", "27d9459c", "bf97222c", "15e6fc2a", "0f91fc71","9b941525", "fae59361", "ceb69ceb", "c2a86459", "12baa8d1","b6c1075e", "e3056a0c", "10d25065", "cb03a442", "e0ec6e0e","1698db3b", "4c98a0be", "3278e964", "9f1f9532", "e0d392df","d3a0342b", "8971f21e", "1b0a7441", "4ba3348c", "c5be7120","c37632d8", "df359f8d", "9b992f2e", "e60b6f47", "0fe3f11d","e54cda54", "1edad891", "ce6279cf", "cd3e7e6f", "1618b166","fd2c1d05", "848fd2c5", "f6fb2299", "f523f357", "a6327623","93a83531", "56cccd02", "acf08162", "5a75ebb5", "6e163697","88d273cc", "de966292", "81b949d0", "4c50901b", "71c65614","e6c6c7bd", "327a140a", "45e1d006", "c3f27b9a", "c9aa53fd","62a80f00", "bb25bfe2", "35bdd2f6", "71126905", "b2040222","b6cbcf7c", "cd769c2b", "53113ec0", "1640e3d3", "38abbd60","2547adf0", "ba38209c", "f746ce76", "77afa1c5", "20756060","85cbfe4e", "8ae88dd8", "7aaaf9b0", "4cf9aa7e", "1948c25c","02fb8a8c", "01c36ae4", "d6ebe1f9", "90d4f869", "a65cdea0","3f09252d", "c208e69f", "b74e6132", "ce77e25b", "578fdfe3","3ac372e6" }};private static string[] Pi_Subkeys = new string[] {"243f6a88", "85a308d3", "13198a2e", "03707344", "a4093822","299f31d0", "082efa98", "ec4e6c89", "452821e6", "38d01377","be5466cf", "34e90c6c", "c0ac29b7", "c97c50dd", "3f84d5b5","b5470917", "9216d5d9", "8979fb1b"};private static long modVal = 1;private static string HexadecimalToBinary(string plainText){string binary = "";int n = plainText.Length;for (int i = 0; i < n; i++){int num = Convert.ToInt32(plainText[i] + "", 16);string binary4B = Convert.ToString(num, 2);binary4B = "0000" + binary4B;binary4B = binary4B.Substring(binary4B.Length - 4);binary += binary4B;}return binary;}private static string BinaryToHexadecimal(string plainText){int num = Convert.ToInt32(plainText, 2);string hexa = num.ToString("x");while (hexa.Length < (plainText.Length / 4)){hexa = "0" + hexa;}return hexa;}private static string HexadecimalXor(string a, string b){a = HexadecimalToBinary(a);b = HexadecimalToBinary(b);string ans = "";for (int i = 0; i < a.Length; i++){ans += (char)(((a[i] - '0') ^ (b[i] - '0')) + '0');}ans = BinaryToHexadecimal(ans);return ans;}private static string AddBinaryModula(string a, string b){int n1 = Convert.ToInt32(a, 16);int n2 = Convert.ToInt32(b, 16);n1 = (int)((n1 + n2) % modVal);string ans = n1.ToString("x");ans = "00000000" + ans;return ans.Substring(ans.Length - 8);}private static string Function(string plainText){string[] a = new string[4];for (int i = 0; i < 8; i += 2){int col = Convert.ToInt32(HexadecimalToBinary(plainText.Substring(i, 2)), 2);a[i / 2] = Substitution_Boxes[i / 2, (int)col];}string ans = AddBinaryModula(a[0], a[1]);ans = HexadecimalXor(ans, a[2]);ans = AddBinaryModula(ans, a[3]);return ans;}private static void KeyGenerate(string key){int j = 0;for (int i = 0; i < Pi_Subkeys.Length; i++){Pi_Subkeys[i] = HexadecimalXor(Pi_Subkeys[i], key.Substring(j, 8));j = (j + 8) % key.Length;}}private static string Round(int time, string plainText){string left, right;left = plainText.Substring(0, 8);right = plainText.Substring(8, 16 - 8);left = HexadecimalXor(left, Pi_Subkeys[time]);string fOut = Function(left);right = HexadecimalXor(fOut, right);return right + left;}public static string Encrypt(string plainText, string key = "01234567ABCDEF00"){if (modVal == 1){for (int i = 0; i < 32; i++){modVal = modVal << 1;}KeyGenerate(key);}for (int i = 0; i < 16; i++){plainText = Round(i, plainText);}string right = plainText.Substring(0, 8);string left = plainText.Substring(8, 16 - 8);right = HexadecimalXor(right, Pi_Subkeys[16]);left = HexadecimalXor(left, Pi_Subkeys[17]);return left + right;}public static string Decrypt(string plainText, string key = "01234567ABCDEF00"){if (modVal == 1){for (int i = 0; i < 32; i++){modVal = modVal << 1;}KeyGenerate(key);}for (int i = 17; i > 1; i--){plainText = Round(i, plainText);}string right = plainText.Substring(0, 8);string left = plainText.Substring(8, 16 - 8);right = HexadecimalXor(right, Pi_Subkeys[1]);left = HexadecimalXor(left, Pi_Subkeys[0]);return left + right;}}
}

4 drive代码


using Legalsoft.Truffer.Algorithm;

private void button1_Click(object sender, EventArgs e)
{
    string src = "123456abcd132536";
    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Source string: " + src + "<br>");
    //string ens = "d748ec383d3405f7";
    string ens = Bowfish_Algorithm.Encrypt(src, "aabb09182736ccdd");
    sb.AppendLine("Crypt string: " + ens + "<br>");
    string dns = Bowfish_Algorithm.Decrypt(ens, "aabb09182736ccdd");
    sb.AppendLine("Decrypt string: " + dns + "<br>");

    webBrowser1.DocumentText = sb.ToString();
}

——————————————————————————

POWER  BY  TRUFFER.CN


using Legalsoft.Truffer.Algorithm;private void button1_Click(object sender, EventArgs e)
{string src = "123456abcd132536";StringBuilder sb = new StringBuilder();sb.AppendLine("Source string: " + src + "<br>");//string ens = "d748ec383d3405f7";string ens = Bowfish_Algorithm.Encrypt(src, "aabb09182736ccdd");sb.AppendLine("Crypt string: " + ens + "<br>");string dns = Bowfish_Algorithm.Decrypt(ens, "aabb09182736ccdd");sb.AppendLine("Decrypt string: " + dns + "<br>");webBrowser1.DocumentText = sb.ToString();
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/670557.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

学习Android的第五天

目录 Android ConstraintLayout 约束布局 简介 ConstraintLayout 约束布局分类 1、相对定位 (Relative positioning) 2、边距 ( Margins ) 3、居中定位和偏向 ( Centering positioning and bias ) 4、环形定位 ( Circular positioning ) 5、对可见性的处理 ( Visibilit…

万物皆可播时代,我们如何把握机遇

在万物皆可播的时代&#xff0c;我们可以通过以下方式来把握机遇&#xff1a; 了解市场需求&#xff1a;通过观察和了解消费者的需求和偏好&#xff0c;发现具有潜力的市场空白。关注时尚、美妆、美食、旅游等领域的发展趋势&#xff0c;掌握最新的流行趋势&#xff0c;结合自…

春运开始,北斗卫星助力盲区来车预警提示

春运开始&#xff0c;北斗卫星助力盲区来车预警提示 近期春运开始&#xff0c;高德地图启动了2024年的“温暖回家路”服务计划&#xff0c;通过数字化服务创新保障春运出行。除了具备自学习能力的新能源导航首发亮相外&#xff0c;还重点升级了盲区会车预警服务。在山区弯道、…

❤ React18 环境搭建项目与运行(地址已经放Gitee开源)

❤ React项目搭建与运行 环境介绍 node v20.11.0 react 18.2 react-dom 18.2.0一、React环境搭建 第一种普通cra搭建 1、检查本地环境 node版本 18.17.0 检查node和npm环境 node -v npm -v 2、安装yarn npm install -g yarn yarn --version 3、创建一个新的React项目…

ABAP 笔记--内表结构不一致,无法更新数据库MODIFY和UPDATE

目录 ABAP 笔记内表结构不一致&#xff0c;无法更新数据库MODIFY和UPDATE ABAP 笔记 内表结构不一致&#xff0c;无法更新数据库 MODIFY和UPDATE 如果是使用MODIFY或者UPDATE

Live800:从客户反馈中学习与改进,塑造卓越的企业客户服务

在当今的商业环境中&#xff0c;客户反馈已经成为企业改进产品和服务&#xff0c;提升客户满意度&#xff0c;增强品牌形象的重要工具。今天将以企业客户服务为例&#xff0c;探讨如何从客户反馈中学习和改进&#xff0c;包括收集客户反馈、分析客户反馈、实施改进措施等方面。…

远程主机可能不符合 glibc 和 libstdc++ Vs Code 服务器的先决条件

vscode连接远程主机报错&#xff0c;原因官方已经公布过了&#xff0c;需要远程主机 glibc>2.28&#xff0c;所以Ubuntu18及以下版本没法再远程连接了&#xff0c;其他Linux系统执行ldd --version查看glibc版本自行判断。 解决方案建议&#xff1a; 不要再想升级glibc了 问题…

Golang GC 介绍

文章目录 0.前言1.发展史2.并发三色标记清除和混合写屏障2.1 三色标记2.2 并发标记问题2.3 屏障机制Dijkstra 插入写屏障Yuasa 删除写屏障混合写屏障 3.GC 过程4.GC 触发时机5.哪里记录了对象的三色状态&#xff1f;6.如何观察 GC&#xff1f;方式1&#xff1a;GODEBUGgctrace1…

机器学习 | 探索朴素贝叶斯算法的应用

朴素贝叶斯算法是一种基于贝叶斯定理和特征条件独立假设的分类算法。它被广泛应用于文本分类、垃圾邮件过滤、情感分析等领域&#xff0c;并且在实际应用中表现出色。 朴素贝叶斯法是基于贝叶斯定理与特征条件独立假设的分类方法&#xff1a; 1&#xff09;对于给定的待分类项r…

Architecture Lab:Part C【流水线通用原理/Y86-64的流水线实现/实现IIADDQ指令】

目录 任务描述 知识回顾 流水线通用原理 Y86-64流水线实现&#xff08;PIPE-与PIPE&#xff09; 开始实验 IIADDQ指令的添加 优化 ncopy.ys 仅用第四章知识&#xff0c;CEP11.55 8x1展开&#xff0c;CPE9.35 8x1展开2x1展开消除气泡&#xff0c;CPE8.10 流水线化通过…

算法每日一题: 使用循环数组所有元素相等的最少秒数 | 哈希

大家好&#xff0c;我是星恒&#xff0c;今天给大家带来的是一道需要感觉规律的题目&#xff0c;只要读懂题目中的规律&#xff0c;就可以做出来了 这道题用到了哈希&#xff0c;还有一个关键点比较类似循环队列 题目&#xff1a;leetcode 2808 给你一个下标从 0 开始长度为 n…

Postman发送带登录信息的请求

环境&#xff1a;win10Postman10.17.7 假设有个请求是这样的&#xff1a; RequiresPermissions("tool:add") PostMapping(value"/predict") ResponseBody /** * xxx * param seqOrderJson json格式的参数 * return */ public String predictSampleIds(Req…

svg基础(三)分组、渐变

上一篇文章简单介绍了svg常用标签及其属性,本篇主要介绍分组&#xff0c;渐变 1 分组<g> 分组容器 添加到g元素上的变换会应用到其所有的子元素上添加到g元素的属性会被其所有的子元素继承定义复杂对象&#xff0c;可通过<use>元素引用 1.1 分组 <svg>&…

EasyExcel分页上传数据

EasyExcel分页上传数据 一、实例 controller上传入口 PostMapping("/upload")ResponseBodyLog(title "导入工单", businessType BusinessType.IMPORT)public AjaxResult uploadFile(HttpServletRequest request, MultipartFile files) throws Exceptio…

Node.js+Express+Mysql服务添加环境变量

1、使用dotenv插件 1&#xff09;安装插件&#xff1a;npm install dotenv-cli --save-dev 2&#xff09;在项目根目录下添加对应的 .env 配置文件&#xff1b; // .env配置文件内容 MODEdevelopment, BASE_URLhttp://127.0.0.1:80813) 在启动命令中设置对应的加载文件&#…

springboot159基于springboot框架开发的景区民宿预约系统的设计与实现

简介 【毕设源码推荐 javaweb 项目】基于springbootvue 的 适用于计算机类毕业设计&#xff0c;课程设计参考与学习用途。仅供学习参考&#xff0c; 不得用于商业或者非法用途&#xff0c;否则&#xff0c;一切后果请用户自负。 看运行截图看 第五章 第四章 获取资料方式 **项…

STM32内部Flash

目录 一、内部Flash简介 二、内部Flash构成 1. 主存储器 2. 系统存储区 3. 选项字节 三、内部Flash写入过程 1. 解锁 2. 页擦除 3. 写入数据 四、工程空间分布 某工程的ROM存储器分布映像&#xff1a; 1. 程序ROM的加载与执行空间 2. ROM空间分布表 一、内部Flash…

2024.3.28-29日ICVS-AI智能汽车产业峰会(杭州)

本次安策将携手泰雷兹一起&#xff0c;参展ICVS2024第四届AI智能汽车产业峰会(杭州)&#xff0c;2024年3月28日-29日&#xff0c;欢迎新老朋友参加和莅临27号展台交流。 随着自动驾驶汽车政策密集落地。从我国四部门联合发布《关于开展智能网联汽车准入和上路通行试点工作的通知…

【头歌·计组·自己动手画CPU】一、计算机数据表示(讲解版) 【计算机硬件系统设计】

&#x1f57a;作者&#xff1a; 主页 我的专栏C语言从0到1探秘C数据结构从0到1探秘Linux &#x1f618;欢迎关注&#xff1a;&#x1f44d;点赞&#x1f64c;收藏✍️留言 &#x1f3c7;码字不易&#xff0c;你的&#x1f44d;点赞&#x1f64c;收藏❤️关注对我真的很重要&…

五、Redis之发布订阅及事务管理

5.1 发布订阅 5.1.1 Redis 发布订阅 (pub/sub) 是一种消息通信模式&#xff1a;发送者 (pub) 发送消息&#xff0c;订阅者 (sub) 接收消息。Redis 客户端可以订阅任意数量的频道。下图展示了频道 channel1 &#xff0c;以及订阅这个频道的三个客户端 —— client1 、client2 …