[{"content":"The most common Abacus is the 2\/5 Abacus. This means that there are two beads on above the bar and 5 beads below the bar.\nThis abacus is in base 10 this means that each rod\/column is each of the separate 10s position. For the example below this can represent every number from 0 to 99999.\nStarting point When retesting it to 0 all of the beads will be not touching the mid bar. This means that the top beads are up and the bottom beads are down.\nThe top beads count as 5x that columns value. The bottom beads count as 1x that columns value.\nAdding on the Abacus When adding a number to the Abacus you start with the highest digit first with the bottom beads first. When you get to a mutable of 5 you reset the lower beads of the column and set a single top bead. When you have both top beads set from a single column then you unset them and go to the column to the left and set a bottom bead. This is just like a regular carryover in addition.\nSubtracting on the Abacus When subtracting a number on the Abacus you start with the highest digit first and remove the beads of the corresponding row. If you cant do that with the beads in the bottom row. You move one of the top rows down and then add 5 beads to the bottom row. If you don&rsquo;t have any of the 5&rsquo;s set then you subtract from the row to the left and set one of the 5&rsquo;s and 5 of the 1&rsquo;s.\nHave fun with the interactive Abacus and see if you can add and subtract numbers on it.\n","permalink":"https:\/\/generalzero.org\/posts\/2025\/02\/how-to-use-an-abacus\/","summary":"<p>The most common Abacus is the 2\/5 Abacus. This means that there are two beads on above the bar and 5 beads below the bar.<\/p>\n<p>This abacus is in base 10 this means that each rod\/column is each of the separate 10s position. For the example below this can represent every number from 0 to 99999.<\/p>\n\n\n<iframe src=\"\/abicus\/index.html\" width=\"100%\" height=\"700\" frameborder=\"0\"><\/iframe>\n\n\n<h3 id=\"starting-point\">Starting point<\/h3>\n<p>When retesting it to 0 all of the beads will be not touching the mid bar. This means that the top beads are up and the bottom beads are down.<\/p>","title":"How to use an Abacus"},{"content":"Orbits This will be a multi part series about Orbits and the GPS system.\nPart 1: Satellite Orbits (This Post) Part 2: GPS Satellites and Distances [WIP] Part 3: Correcting for non-precise time [WIP] Before getting into the GPS part of this series we first need to know some simple things about GPS.\nThere are many different GPS Satellites but they operate on the same principal. They have multiple atomic clocks which are used to get a precise time. Then send that time in a RF signal to earth so that devices can retrieve that time and use it to calculate how long it took to get there. Using the time distance and knowing that the RF signal will be traveling at the Speed of light you can get the distance from the satellite to the receiver(You). Using at least 3 (when you also have a atomic clock) or 4 you can figure out where in space you are located. Then you can convert this to latitude, longitude and height on the earth.\nThe USA-132 GPS Satellite has 4 atomic clocks. 2 Cesium atomic clocks that operate at 9.192GHz and 2 Rubidium atomic clocks that operate at 6.835GHz.\nGPS Satellites are satellites not in geosynchronous orbit(Travel at the same speed as the earths rotation). They actually orbit the earth a bit over 2 times a day. You can see this in the Getting the Satellite Parameters Section.\nSo the first step is knowing where the GPS satellites were\/are at a specific time. So here is a quick crash corse on Orbital Mechanics.\nIntroduction to 2D Orbital Mechanics Lets break this into\n2D Ellipse Vocabulary: Perigee: The point where the satellite is the nearest to the earth. It is also when the satellite has the greatest velocity and acceleration. Apogee: The point where the satellite is the farthest from the earth. It is also when the satellite has the least velocity and acceleration. Periapsis: The distance from the earth to the perigee point. Apoapsis: The distance from the earth to the apogee point. Focus (Foci): The points in an ellipse where the mass must reside so that the orbit is periodic. One of these spots is where the Earth is. Semi-minor Axis: The shortest radius of the ellipse. Measured from the Perigee to the center of the ellipse. Semi-major Axis (a): The longest radius of the ellipse. Measured from the Apogee to the center of the ellipse. Eccentricity (e): The ratio of the Perigee and Apogee radius. Describes how circular the orbit is. Mean Motion: The average rate of speed measured in rotations per day. Now that we have the vocabulary lets look at the Math the connects this together.\nUsing Mean Motion to find the Semi-major Axis:\n$$ \\mu = Earths_Gravitational_Constant = 3.986004418e^{14} ; m^3\/s^2 \\\\ semi_major_axis = \\left( \\frac{\\mu}{\\left(\\frac{2\\pi * mean_motion}{86400}\\right)^2} \\right)^{\\frac{1}{3}} $$\nCalculating the Semi-minor Axis from the Semi-major Axis :\n$$ semi_minor_axis = semi_major_axis * \\sqrt{1 - eccentricity^2)} $$\nCalculating the Focus\/Earth Position:\n$$ earth_offset = semi_major_axis * eccentricity $$\nCalculating the Position of the Satellite The Mean Anomaly is the value given to us as a parameter from the satellite equation. Since this is the average anomaly it is easy to advance this parameter forwards or backwards using a constant. This allows us to not have to account for the change in velocity and acceleration depending how close it is to earth.\nUsing both the Mean Anomaly and Eccentricity you can calculate the Eccentric Anomaly. This is an intermediary calculation that is used to calculate the location of the satellite. The way to calculate this is done in a infinite series but since each change approaches zero you can set a limit. This intermediate step is the angle from the center to where the satellite would be if the orbit was a circle.\nTrue Anomaly is the angle from the earth to the satellite&rsquo;s position. If this is 0 degrees then the satellite is at the Apogee. This is calculated using the Eccentric Anomaly and Eccentricity using Trigonometry.\nDefining the position along an orbit:\nTrue Anomaly: The angle from the perigee to the satellite position. This is centered on earth. Mean Anomaly: The average motion of the satellite throughout its orbit. Is computed from the earth gravitational constant and the semi-major axis. This is centered on the center of the ellipse orbit. Eccentric Anomaly: This is the location where the satellite would be if the orbit was a circle. This is used to calcualte the true anomaly. This is centered on the center of the ellipse orbit. This interactive will show you the relationship between each of the Anomalies. You can change the settings so that you get a better feel how each of the parameters influence each other.\nUsing Math Eccentric Anomaly is calculated using steps to approach the correct value. This is done by nudging the value closer to the real value. So you have to use a cutoff value of some small number.\nUse Mean Anomaly to calculate Eccentric Anomaly:\n$$ E_{k+1} = E_k - \\dfrac{E_k - e \\sin(E_k) - M}{1 - e \\cos(E_k)} \\\\ |E_{k+1} - E_k| \\leq \\delta_{\\text{cutoff}} ), with ( \\delta_{\\text{cutoff}} = 1 \\times 10^{-8} ). $$\nSince True Anomaly has the same x value using some Trigonometry equations you can get the angle from the orbit perigee.\nEccentric to True Anomaly:\n$$ true_anomaly = 2 * \\mathrm{arctan2} {( \\sqrt{ 1 + eccentricity } * \\sin{(\\dfrac{ecc_anomaly}{2})}, \\sqrt{ 1 - eccentricity } * \\cos{\\dfrac{ecc_anomaly}{2}} )} $$\nNow you have the true angle from the earth and can use that to calculate the distance from the earth with the equation below.\nThe Distance from the earth to the satellite:\n$$ radius = semi_major_axis * (1 - eccentricity^2) \/ (1 + eccentricity * cos(trueAnomaly) ) $$\n3D Elliptical Satellite Orbits As you transition from 2D to 3D there is more vocab that we need to define. So we can get in to the orbital parameters.\n3D Elliptical Vocabulary:\nAscending Node: The point where the orbit passes through the XY axis going from negative Z value to positive Z value. This is the point where the Yellow and Teal arcs meet. Descending Node: The point where the orbit passes through the XY axis going from positive Z value to negative Z value Line of Nodes: The line on the XY plane that goes through the Ascending and Descending Nodes. To define the 3D part of the elliptical orbit three parameters must be given. Where Inclination, Argument of periapsis, and RANN are rotations of the 2D elliptical orbit in the X, Y and Z axis.\nInclination: The angle that the orbit is tilted from the equator towards the north pole. RAAN: Is the angle from the x axis to where the orbit intersects the xy plane where the satellite came from below the xy plane to above the xy plane. Aka Right Ascension of the Ascending Node or Longitude of the Ascending Node Argument of periapsis: Is the angle from the Ascending Node to the Perigee. Here is a 3d Representation of the Orbit. Have fun modifying the orbital parameters and using the mouse to change the camera.\nGetting the Satellite Parameters There is a website that you can use to get the parameters. Its called CelesTrak which is a 501(c)(3) non-profit that tracks this information.\nHere are the information for the GPS satellite NAVSTAR 43 (USA 132)(ID=24876).\ncurl https:\/\/celestrak.org\/NORAD\/elements\/gp.php?CATNR=24876&amp;FORMAT=TLE NAVSTAR 43 (USA 132) 1 24876U 97035A 24345.27731839 .00000058 00000+0 00000+0 0 9990 2 24876 55.7327 120.2454 0086137 54.9413 305.8431 2.00561901200849 Parsing the Information The way the TLE data is formatted it is a strict standard with constant width information with fixed decimal places. You can see how the data is parsed below. The data we are looking for is in the second line which contains\nInclination in degrees (55.7327\u00b0) Right Ascension of the Ascending Node (RAAN) in degrees (120.2454\u00b0) Eccentricity but only containing the decimal part (0086137 = 0.0086137) Argument of periapsis in degrees (54.9413\u00b0) Mean Anomaly in degrees (305.8431\u00b0) Mean Motion in revolutions per day (2.00561901200849) Parsing the Parameter Information:\nfunction setParametersFromTLE(lines) { const line2 = lines[2]; \/\/2 24876 55.7327 120.2454 0086137 54.9413 305.8431 2.00561901200849 \/\/ Parse line 2 for the orbital parameters let inclination = parseFloat(line2.substring(8, 16)).toFixed(4); \/\/ 55.7327 Degrees let raan = parseFloat(line2.substring(17, 25)).toFixed(4); \/\/ 120.2454 Degrees let eccentricityStr = line2.substring(26, 33).trim(); \/\/ &#34;0086137&#34; let eccentricity = parseFloat(&#39;0.&#39; + eccentricityStr).toFixed(6); \/\/ Convert to decimal 0.0086137 let argument = parseFloat(line2.substring(34, 42)).toFixed(4); \/\/ 54.9413 Degrees let manomaly = parseFloat(line2.substring(43, 51)).toFixed(4); \/\/ 305.8431 Degrees let mmotion = parseFloat(line2.substring(52, 63)).toFixed(10); \/\/ 2.00561901200849 Revolutions per day return { inclination, raan, eccentricity, argument, manomaly, mmotion }; } 3D Location of the Satellite Using the same EQs from before you can find out the location of the satellite on the 2D plane. Adter that you can use the inclination, raan and argument variables to rotate the X,Y and Z axis.\nPutting it all together:\nfunction keplerToECI(semiMajorAxis, eccentricity, i, raan, omega, M) { \/\/ Solve Kepler&#39;s equation to find Eccentric Anomaly (E) let ecc_anomaly = mean2eccentric(M, eccentricity); \/\/ Compute True Anomaly (nu) from ecc_anomaly const trueAnomaly = eccToTrueAnomaly(ecc_anomaly, eccentricity); \/\/ Compute orbital radius (r) const radius = getOrbitalRadius(trueAnomaly, semiMajorAxis, eccentricity); \/\/ Position in the orbital plane const xPrime = radius * Math.cos(trueAnomaly); const yPrime = radius * Math.sin(trueAnomaly); \/\/ Rotate to ECI coordinates const cosOmega = Math.cos(THREE.MathUtils.degToRad(raan)); const sinOmega = Math.sin(THREE.MathUtils.degToRad(raan)); const cosInclination = Math.cos(THREE.MathUtils.degToRad(i)); const sinInclination = Math.sin(THREE.MathUtils.degToRad(i)); const cosArgPerigee = Math.cos(THREE.MathUtils.degToRad(omega)); const sinArgPerigee = Math.sin(THREE.MathUtils.degToRad(omega)); const x1 = xPrime * cosArgPerigee - yPrime * sinArgPerigee; const y1 = xPrime * sinArgPerigee + yPrime * cosArgPerigee; const z1 = 0; const x2 = x1; const y2 = y1 * cosInclination - z1 * sinInclination; const z2 = y1 * sinInclination + z1 * cosInclination; const xECI = x2 * cosOmega - y2 * sinOmega; const yECI = x2 * sinOmega + y2 * cosOmega; const zECI = z2; return new THREE.Vector3(xECI \/ scale, yECI \/ scale, zECI \/ scale); \/\/ Scale down for visualization } ","permalink":"https:\/\/generalzero.org\/posts\/2024\/12\/satellite-orbits\/","summary":"<h2 id=\"orbits\">Orbits<\/h2>\n<p>This will be a multi part series about Orbits and the GPS system.<\/p>\n<ul>\n<li>Part 1: Satellite Orbits (This Post)<\/li>\n<li><del>Part 2: GPS Satellites and Distances [WIP]<\/del><\/li>\n<li><del>Part 3: Correcting for non-precise time [WIP]<\/del><\/li>\n<\/ul>\n<p>Before getting into the GPS part of this series we first need to know some simple things about GPS.<\/p>\n<p>There are many <a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_GPS_satellites\">different GPS Satellites<\/a> but they operate on the same principal. They have multiple atomic clocks which are used to get a precise time. Then send that time in a RF signal to earth so that devices can retrieve that time and use it to calculate how long it took to get there. Using the time distance and knowing that the RF signal will be traveling at the Speed of light you can get the distance from the satellite to the receiver(You). Using at least 3 (when you also have a atomic clock) or 4 you can figure out where in space you are located. Then you can convert this to latitude, longitude and height on the earth.<\/p>","title":"Satellite Orbits"},{"content":"This will be a first of many posts on creating Crypto Primitives from Scratch.\nThe code will have:\nTested against production implementations Commented to give information about more complex instructions Have common name variables and function names to give a better view of data flow Be done in python since it is easy to read. Crypto From Scratch Series For a list of all of these implementations look at my https:\/\/github.com\/GeneralZero\/ChaCha-and-Salsa where I will be posting finished versions of common Encryption, Decryption, Hashing, Key Generation and Key Enchanges. Also this page will be update with new Algorithums.\nSymetric Encryption DES\/3DES Symetric Encryption ChaCha\/XChaCha Symetric Encryption Salsa\/XSalsa Symetric Encryption AES Symetric Encryption RC4 Symetric Encryption TEA Symetric Encryption (TODO) Asymetric Encryption RSA Asymetric Encryption RSA PKCS#1 v1.5 Asymetric Encryption RSA PKCS#1 OAEP Asymetric Encryption ElGamal Asymetric Encryption ECC Asymetric Encryption (TODO) Message Authentication Codes HMAC Message Authentication Code Poly1305 Message Authentication Code CMAC Message Authentication Code GMAC Message Authentication Code KMAC (TODO) OMAC (TODO) Hash Functions MD2 Hash Function MD4 Hash Function MD5 Hash Function SHA1 Hash Function SHA2 (SHA224, SHA256, SHA384, SHA512) Hash Function SHA3 (SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE-128, SHAKE-256, Keccak-224, Keccak-256, Keccak-384, Keccak-512) Hash Function Blake (Blake224, Blake256, Blake384, Blake512) Hash Function Blake2 (Blake2b, Blake2s) Hash Function Gimli Hash Function Key Exchange Diffie Hellman Key Exchange ECDH Key Exchange Extended Triple Diffie-Hellman Key Exchange Signature Generation DSA ECDSA EdDSA RSA DKIM (TODO) Key Derivation PBKDF1 Key Derivation PBKDF2 Key Derivation Argon2 Key Derivation BCrypt Key Derivation Double Rachet Key Derivation (TODO) Scrypt Key Derivation Shamir&rsquo;s Secret Sharing Scheme Key Derivation (TODO) ","permalink":"https:\/\/generalzero.org\/cryptofromscratch\/crypto-from-scratch\/","summary":"How Crypto Works with readable inplmentations","title":"Crypto From Scratch: Intro"},{"content":"If you are looking for a full information on how DES works look at this link.\nDES likes doing permutations at the bit level of everything.\nIt does them on the initial key input before generating the round keys It does them on each block of the input message before splitting it into the left and right inputs During the round it expands the input by 10 bits using a permutation. The main encryption uses a substitution box The output of that substitution box is also permutated To top it off there is a final permutation at the end. Its weird because most of these permutations are reversible and don&rsquo;t really offer any more security but maybe its because its an old algorithm that&rsquo;s why it is what it is.\n3DES 3DES is just DES but done three times and is just as simple as\n#Break input key into keys for 3DES if len(self.key) == 16: key1 = self.key[:8] key2 = self.key[8:16] key3 = key1 elif len(self.key) == 24: key1 = self.key[:8] key2 = self.key[8:16] key3 = self.key[16:24] else: raise Exception(&#34;Invaid Key fror 3DES&#34;) #Do Encryption with first key self._gen_subkeys(key1) message = self.encrypt(message) print(message) #Do Decryption with second key self._gen_subkeys(key2) message = self.decrypt(message) print(message) #Do Encryption with third key self._gen_subkeys(key3) return self.encrypt(message) The encryption key is broken into 8 byte chunks and used to generate the three keys. If the key is only 16 bytes then the first key is the same as the third key. This makes 3DES backwards compatible with DES if both the first and second key are the same. Since it does a encrypt and decrypt the input to the third key will be the original plaintext.\nPython Implementation The code is also located on github. Please don&rsquo;t use this in actual products.\nfrom cryptopals_lib import fixedlen_xor, to_blocks, int_to_bytes class DES(): &#34;&#34;&#34;docstring for DES&#34;&#34;&#34; def __init__(self,key,IV=None): self.sbox = [[14,4,13,1,2,15,11,8,3,10,6,12,5,9,0,7,0,15,7,4,14,2,13,1,10,6,12,11,9,5,3,8, 4,1,14,8,13,6,2,11,15,12,9,7,3,10,5,0,15,12,8,2,4,9,1,7,5,11,3,14,10,0,6,13], [15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10,3,13,4,7,15,2,8,14,12,0,1,10,6,9,11,5, 0,14,7,11,10,4,13,1,5,8,12,6,9,3,2,15,13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9], [10,0,9,14,6,3,15,5,1,13,12,7,11,4,2,8,13,7,0,9,3,4,6,10,2,8,5,14,12,11,15,1, 13,6,4,9,8,15,3,0,11,1,2,12,5,10,14,7,1,10,13,0,6,9,8,7,4,15,14,3,11,5,2,12], [7,13,14,3,0,6,9,10,1,2,8,5,11,12,4,15,13,8,11,5,6,15,0,3,4,7,2,12,1,10,14,9, 10,6,9,0,12,11,7,13,15,1,3,14,5,2,8,4,3,15,0,6,10,1,13,8,9,4,5,11,12,7,2,14], [2,12,4,1,7,10,11,6,8,5,3,15,13,0,14,9,14,11,2,12,4,7,13,1,5,0,15,10,3,9,8,6, 4,2,1,11,10,13,7,8,15,9,12,5,6,3,0,14,11,8,12,7,1,14,2,13,6,15,0,9,10,4,5,3], [12,1,10,15,9,2,6,8,0,13,3,4,14,7,5,11,10,15,4,2,7,12,9,5,6,1,13,14,0,11,3,8, 9,14,15,5,2,8,12,3,7,0,4,10,1,13,11,6,4,3,2,12,9,5,15,10,11,14,1,7,6,0,8,13], [4,11,2,14,15,0,8,13,3,12,9,7,5,10,6,1,13,0,11,7,4,9,1,10,14,3,5,12,2,15,8,6, 1,4,11,13,12,3,7,14,10,15,6,8,0,5,9,2,6,11,13,8,1,4,10,7,9,5,0,15,14,2,3,12], [13,2,8,4,6,15,11,1,10,9,3,14,5,0,12,7,1,15,13,8,10,3,7,4,12,5,6,11,0,14,9,2, 7,11,4,1,9,12,14,2,0,6,10,13,15,3,5,8,2,1,14,7,4,10,8,13,15,12,9,0,3,5,6,11],] self.pre_subkey_permutation = [56,48,40,32,24,16,8,0,57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43,35, 62,54,46,38,30,22,14,6,61,53,45,37,29,21,13,5,60,52,44,36,28,20,12,4,27,19,11,3] self.subkey_permutation = [13,16,10,23,0,4,2,27,14,5,20,9,22,18,11,3,25,7,15,6,26,19,12,1,40,51,30,36,46,54, 29,39,50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31] self.inital_perm = [57,49,41,33,25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21,13,5, 63,55,47,39,31,23,15,7,56,48,40,32,24,16,8,0,58,50,42,34,26,18,10,2, 60,52,44,36,28,20,12,4,62,54,46,38,30,22,14,6] self.expantion_table = [31,0,1,2,3,4,3,4,5,6,7,8,7,8,9,10,11,12,11,12,13,14,15,16,15,16,17,18,19,20, 19,20,21,22,23,24,23,24,25,26,27,28,27,28,29,30,31,0] self.sbox_perm = [15,6,19,20,28,11,27,16,0,14,22,25,4,17,30,9,1,7,23,13,31,26,2,8,18,12,29,5,21,10,3,24] self.final_permutation = [39,7,47,15,55,23,63,31,38,6,46,14,54,22,62,30,37,5,45,13,53,21,61,29, 36,4,44,12,52,20,60,28,35,3,43,11,51,19,59,27,34,2,42,10,50,18,58,26, 33,1,41,9,49,17,57,25,32,0,40,8,48,16,56,24] self.block_size = 64\tself.left_rotations = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1] #Create Subkeys self.key = key self._gen_subkeys(self.key) def _gen_subkeys(self, key): self.subkeys = [&#34;&#34; for _ in range(16)] binary_key = &#34;&#34;.join([&#34;{0:&gt;08b}&#34;.format(int(x)) for x in key]) output_key = &#34;&#34; #Permutate the key using PC1 for index in self.pre_subkey_permutation: output_key += binary_key[index] #Split into Left and Right left_key, right_key = output_key[:28], output_key[28:] for round_num in range(16): #shift_rotate_left the left key left_key = left_key[self.left_rotations[round_num]:] + left_key[:self.left_rotations[round_num]] #shift_rotate_left the right key right_key = right_key[self.left_rotations[round_num]:] + right_key[:self.left_rotations[round_num]] #Join the keys together into a full key full_key = left_key + right_key #Create the subkeys for index in self.subkey_permutation: self.subkeys[round_num] += full_key[index] def _round_opperation(self, round_key, right_message): right_message_expanded = &#34;&#34; s_box_sub = &#34;&#34; s_box_out = &#34;&#34; #Expand the message to 42 bytes using a permutation with duplicate entries for index in self.expantion_table: right_message_expanded += right_message[index] #Xor round key with expanded right message right_message_expanded = fixedlen_xor(round_key, right_message_expanded) #Convert right key into 6bit sbox inputs sbox_inputs = to_blocks(right_message_expanded, 6) #Do sbox subsitution for sbox_index, sbox_input in enumerate(sbox_inputs): #Generate row and coulmn from input data #Row is the first and last bit of the 6bit input row_num = int(sbox_input[0] + sbox_input[-1], 2) #Comumn is the second through fifth bit of the 6bit input column_num = int(sbox_input[1:5], 2) #Do sbox subistution with the correct sub index and round and column index s_box_sub += &#34;{0:&gt;04b}&#34;.format(self.sbox[sbox_index][row_num*16 + column_num]) #Do final permutation on sbox output for index in self.sbox_perm: s_box_out += s_box_sub[index] return s_box_out def _encrypt_message_chunk(self, message_chunk): output_chunk = &#34;&#34; #Do Permentation on the block of the plaintext message for index in self.inital_perm: output_chunk += message_chunk[index] #Break the message into left and right left_message, right_message = output_chunk[:32], output_chunk[32:] #Do rounds for round_key in self.subkeys: #Backup the previous right message right_message_copy = right_message #Do the Round opperation with the round key tmp = self._round_opperation(round_key, right_message) #Set Right message to the xor of the round opperation and the left message right_message = fixedlen_xor(left_message, tmp) #Set the left message to the old right message left_message = right_message_copy #Join the message parts together but swap the left and the right side full_message = right_message + left_message output_chunk = &#34;&#34; #Do final Permutaiton before the data is outputed for index in self.final_permutation: output_chunk += full_message[index] return int_to_bytes(int(output_chunk, 2)) def encrypt(self, message): binary_message = &#34;&#34;.join([&#34;{0:&gt;08b}&#34;.format(int(x)) for x in message]) output_message = b&#34;&#34; #Opperate on each of the 64 byte chunks for chunk in to_blocks(binary_message, self.block_size): output_message += self._encrypt_message_chunk(chunk) return output_message def encrypt_3(self, message): #Break input key into keys for 3DES if len(self.key) == 16: key1 = self.key[:8] key2 = self.key[8:16] key3 = key1 elif len(self.key) == 24: key1 = self.key[:8] key2 = self.key[8:16] key3 = self.key[16:24] else: raise Exception(&#34;Invaid Key fror 3DES&#34;) #Do Encryption with first key self._gen_subkeys(key1) message = self.encrypt(message) print(message) #Do Decryption with second key self._gen_subkeys(key2) message = self.decrypt(message) print(message) #Do Encryption with third key self._gen_subkeys(key3) return self.encrypt(message) def decrypt(self, message): binary_message = &#34;&#34;.join([&#34;{0:&gt;08b}&#34;.format(int(x)) for x in message]) output_message = b&#34;&#34; #Decryption is the same as encryption but with the subkeys in reverse order. #Reverse the order of the subkeys self.subkeys.reverse() #Opperate on each of the 64 byte chunks for chunk in to_blocks(binary_message, self.block_size): output_message += self._encrypt_message_chunk(chunk) return output_message def decrypt_3(self, message): #Break input key into keys for 3DES if len(self.key) == 16: key1 = self.key[:8] key2 = self.key[8:16] key3 = key1 elif len(self.key) == 24: key1 = self.key[:8] key2 = self.key[8:16] key3 = self.key[16:24] else: raise Exception(&#34;Invaid Key fror 3DES&#34;) #Do Decryption with third key self._gen_subkeys(key3) message = self.decrypt(message) print(message) #Do Encryption with second key self._gen_subkeys(key2) message = self.encrypt(message) print(message) #Do Decryption with first key self._gen_subkeys(key1) message = self.decrypt(message) return message if __name__ == &#39;__main__&#39;: des1 = DES(b&#34;64bitKey&#34;) ct = des1.encrypt(b&#34;Secret Message!!&#34;) #print(ct) pt = des1.decrypt(ct) #print(pt) des2 = DES(b&#34;64bitKey32bitKey16bitKey&#34;) ct = des2.encrypt_3(b&#34;Secret Message!!&#34;) print(ct) pt = des2.decrypt_3(ct) print(pt) As always don&rsquo;t use this code for sensitive information and email me at crypto[at]generalzero.org with any corrections.\n","permalink":"https:\/\/generalzero.org\/cryptofromscratch\/crypto-from-scratch-des-3des\/","summary":"DES is mostly just static substitutions, and 3DES is just DESx3.","title":"Crypto From Scratch: DES\/3DES"},{"content":"Author Note: Its been a while but I will be trying to update this blog semi-regularly with new posts of things I have worked on.\nI did a lot of research into answering the interview question as in depth as I can and still present it to a semi-technical audience. The Slides are on located https:\/\/slides.com\/generalzero\/how-do-i-google and are not complete but do go into detail of How physical keyboards work, the USB protocol to the computer and a general view on how that information is translated into events for the program to process.\nMessage me at slides[at]generalzero.org with any questions or corrections you have.\n","permalink":"https:\/\/generalzero.org\/posts\/2021\/02\/what-happens-when\/","summary":"<p><em>Author Note: Its been a while but I will be trying to update this blog semi-regularly with new posts of things I have worked on.<\/em><\/p>\n<p>I did a lot of research into answering the interview question as in depth as I can and still present it to a semi-technical audience. The Slides are on located <a href=\"Presentation\">https:\/\/slides.com\/generalzero\/how-do-i-google<\/a> and are not complete but do go into detail of How physical keyboards work, the USB protocol to the computer and a general view on how that information is translated into events for the program to process.<\/p>","title":"What Happens When I go to google.com"},{"content":"Recently I changed my haproxy configuration to support Client Certificates to login in to services through the Web from outside my internal network. This will be broken down in to mutable parts so that it is easier to read.\nIf you have not created you Client Certificate see Part 1.\nIf you have not configured haproxy to accept Client Certificates see Part 2.\nCreating Client Certificates Configuring Haproxy to accept them Configuring Haproxy to reverse proxy to your web applications Adding your Client Certificate to your browser If you have gotten through everything else than this will be easy\n#####Chrome\nOpen Google Chrome. Open the menu at the top right corner and select Settings. Select Show Advanced Settings &gt; Manage Certificates. Click the Import button The previous step should launch a browser which you can use to navigate to the directory where your client certificate file (usually a PKCS12 file with the .p12 or .pfx extension) is stored. Select the file and enter the required password. If you succeed, you should see a notification that says &ldquo;Successfully restored your security certificate(s) and private key(s).&rdquo; (or something to that effect. Click OK to proceed. #####Firefox\nLaunch Firefox and click the menu icon (3 horizontal lines) found in the upper-right-corner of the browser. After that, click the Preferences icon. Go to the Certificates tab and then click the View Certificates button. The previous step should have launched the Firefox Certificate Manager. Click the Your Certificates tab and then click the Import button. The previous step should launch a browser which you can use to navigate to the directory where your client certificate file (usually a PKCS12 file with the .p12 or .pfx extension) is stored. Select the file and enter the required password. If you succeed, you should see a notification that says &ldquo;Successfully restored your security certificate(s) and private key(s).&rdquo; (or something to that effect. Click OK to proceed. ","permalink":"https:\/\/generalzero.org\/posts\/2016\/03\/client-ssl-certs-for-remote-systems-administration-part-3\/","summary":"<p>Recently I changed my haproxy configuration to support Client Certificates to login in to services through the Web from outside my internal network. This will be broken down in to mutable parts so that it is easier to read.<\/p>\n<p><strong>If you have not created you Client Certificate see <a href=\"__GHOST_URL__\/client-ssl-certs-for-remote-systems-administration-part-1\">Part 1<\/a>.<\/strong><\/p>\n<p><strong>If you have not configured haproxy to accept Client Certificates see <a href=\"__GHOST_URL__\/client-ssl-certs-for-remote-systems-administration-part-2\">Part 2<\/a>.<\/strong><\/p>\n<ul>\n<li><del>Creating Client Certificates<\/del><\/li>\n<li><del>Configuring Haproxy to accept them<\/del><\/li>\n<li><del>Configuring Haproxy to reverse proxy to your web applications<\/del><\/li>\n<li>Adding your Client Certificate to your browser<\/li>\n<\/ul>\n<p>If you have gotten through everything else than this will be easy<\/p>","title":"Client SSL Certs for Remote Systems Administration Part 3"},{"content":"Recently I changed my nginx configuration to support Client Certificates to login in to services through the Web from outside my internal network. This will be broken down in to mutable parts so that it is easier to read.\nIf you have not created you Client Certificate see Part 1.\nCreating Client Certificates Configuring Haproxy to accept them Configuring Haproxy to reverse proxy to your web applications Adding your Client Certificate to your browser ####Configuring Haproxy to Accept Client Certificates\nThis part is actually pretty easy assuming that you have ssl enabled on the connection you only need to add 3 lines.\nfrontend external-https bind *:443 ssl crt \/etc\/haproxy\/certs\/generalzero.org.pem ca-file \/etc\/haproxy\/certs\/client.crt verify optional crt-ignore-err all Thats it.\n####Configuring Haproxy to reverse proxy to your web applications\nNow we can configure the Reverse Proxy to validate certificates before going to the internal services.\nacl cert-acl url_beg \/cerrt AND if { ssl_fc_has_crt } use_backend cert if cert-acl You can also make it so that you can have another site when ssl_client is not verified like this\nbackend cert server cert-server 127.0.0.1:8181 check Continue to the next Part 3\n","permalink":"https:\/\/generalzero.org\/posts\/2016\/03\/client-ssl-certs-for-remote-systems-administration-part-2\/","summary":"<p>Recently I changed my nginx configuration to support Client Certificates to login in to services through the Web from outside my internal network. This will be broken down in to mutable parts so that it is easier to read.<\/p>\n<p><strong>If you have not created you Client Certificate see <a href=\"__GHOST_URL__\/client-ssl-certs-for-remote-systems-administration-part-1\">Part 1<\/a>.<\/strong><\/p>\n<ul>\n<li><del>Creating Client Certificates<\/del><\/li>\n<li>Configuring Haproxy to accept them<\/li>\n<li>Configuring Haproxy to reverse proxy to your web applications<\/li>\n<li>Adding your Client Certificate to your browser<\/li>\n<\/ul>\n<p>####Configuring Haproxy to Accept Client Certificates<\/p>","title":"Client SSL Certs for Remote Systems Administration Part 2"},{"content":"Recently I changed my nginx configuration to support Client Certificates to login in to services through the Web from outside my internal network. This will be broken down in to mutable parts so that it is easier to read.\nCreating Client Certificates Configuring haproxy to accept them Configuring haproxy to reverse proxy to your web applications Adding your Client Certificate to your browser ####Creating Client Certificates This is a tutorial on creating your self signed Client Certificate. Unlike self signed Certificates their is no ugly page saying that this is not signed by a secure Third Party which is good for us.\n#####Create a Certificate Authority root This command creates a Certificate Authority so we can sign the Client Certificate.\nopenssl genrsa -des3 -out ca.key 4096 openssl req -new -x509 -days 365 -key ca.key -out ca.crt Organization &amp; Common Name is the DNS name of the server. What I did is create a wild star so that I can use it for other projects later on down the road.\nCreate the Client Key and CSR This Command creates the Client Certificate and signs it with the Certificate Authority that we created in the last section.\nopenssl genrsa -des3 -out client.key 4096 openssl req -new -key client.key -out client.csr openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt Organization &amp; Common Name can be anything you want but I ususaly keep it as the username of the Person that will use it\nConvert Client Key to PKCS Most browsers accept PKCS#12 as the format for Client Keys. This command will convert the client cert in to PKCS#12 format.\nopenssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12 Convert Client Key to (combined) PEM This command combinds client.p12 certificate and client.key private key into a single PEM file for programs using openssl.\nopenssl pkcs12 -in client.p12 -out client.pem -clcerts Continue to Part2\n","permalink":"https:\/\/generalzero.org\/posts\/2016\/03\/client-ssl-certs-for-remote-systems-administration-part-1\/","summary":"<p>Recently I changed my nginx configuration to support Client Certificates to login in to services through the Web from outside my internal network. This will be broken down in to mutable parts so that it is easier to read.<\/p>\n<ul>\n<li>Creating Client Certificates<\/li>\n<li>Configuring haproxy to accept them<\/li>\n<li>Configuring haproxy to reverse proxy to your web applications<\/li>\n<li>Adding your Client Certificate to your browser<\/li>\n<\/ul>\n<p>####Creating Client Certificates\nThis is a tutorial on creating your self signed Client Certificate. Unlike self signed Certificates their is no ugly page saying that this is not signed by a secure Third Party which is good for us.<\/p>","title":"Client SSL Certs for Remote Systems Administration Part 1"},{"content":" Devices have been getting more user friendly as new devices, services and software comes out. Some of the new services do come with a price affecting security. Specifically one of the newer services to come around is Smart TVs. These devices are mostly beneficial but recently this has not been as true as before. Some of these device have microphones and video cameras that are always on. This can be helpful in situations to simplify our life but depending on where that data is processed it could be sending the data back to a server and getting information that it shouldn\u2019t. This is true with most of the device that have recording devices that are always on because it takes a lot of processing power to do these operation and the device is not suitable for those computations. But this could be negative for the user because the user does not know what the company is using that information for.\nI did some research into this on some of the big name brands like\nLG Smart TV Xbox Kinect Amazon Echo GM\u2019s Onstar Google\u2019s Waze Hello\u2019s Sense And more So I did some research on what and how they are sending back to a central server for processing or for collection in some cases This information could be sold to third parties with out the knowledge of the users. I also looked in to ways of disabling the options if possible and if they are being securely sent over to the server.\nFinally i did some research on the privacy policies of these companies to see what they said about collection of data and how the deal with the information on the server and who they sell and\/or distribute it to.\nThis table shows all of the information that I have gathered compared against one another.\nSamsung Smart TV Xbox Connect Amazon Echo GMs OnStar Google Waze Hello Sense Video Recording No Yes No No No No Audio Recording Yes Yes Yes Yes Yes Yes Recording Other Information No Yes*** The Xbox also records your heartbeat, simple emotion state and can do voice and facial recognition on all people in view of the camera. No Yes*** OnStar is able to track GPS and other car information. They are able to get this information even if you are not paying for the service or bought a car that comes with OnStar. Yes*** Google Waze is able to get contact information about the user if they choose to link a social networking account like Facebook, Linkedin, etc. No Disable Recording Setting Default but can be disabled Default but can be disabled No Default cannot be disabled Yes Yes Data Outbound Encrypted No Yes Yes Unknown Unknown Unknown Data Inbound Encrypted No Yes Yes Unknown Unknown Unknown Privacy Policy Data used as Samsung Wishes Data used as Microsoft Wishes Voice data not used*** Amazon does not use the voice data its self but it does use the text information from the voice data. Data used as Onstar Wishes Data used as Waze Wishes Data used as Hello Wishes Third Party Privacy Policy Data used as Nuance Communications Wishes No specified third parties No specified third parties No specified third parties No specified third parties No specified third parties NSA Data Access Unencrypted is picked by NSA Part of PRISM Unknown OnStar affiliation with Law Enforcement Part of PRISM Unlikely ","permalink":"https:\/\/generalzero.org\/posts\/2015\/05\/smart-devices-feature-or-data-collection\/","summary":"<link rel=\"stylesheet\" href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.6\/css\/bootstrap.min.css\" integrity=\"sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7\" crossorigin=\"anonymous\">\n<p>Devices have been getting more user friendly as new devices, services and software comes out. Some of the new services do come with a price affecting security. Specifically one of the newer services to come around is Smart TVs. These devices are mostly beneficial but recently this has not been as true as before. Some of these device have microphones and video cameras that are always on. This can be helpful in situations to simplify our life but depending on where that data is processed it could be sending the data back to a server and getting information that it shouldn\u2019t. This is true with most of the device that have recording devices that are always on because it takes a lot of processing power to do these operation and the device is not suitable for those computations. But this could be negative for the user because the user does not know what the company is using that information for.<\/p>","title":"Smart Devices Feature or Data Collection"},{"content":"This is how I make Toto embed MathJax in to the page using Tex markup.\n&lt;script type=&quot;math\/tex; mode=display&quot;&gt; \\begin{align} x &amp;= 100011_2 \\\\ &amp;= 100_2 * 2^3 + 011_2 \\end{align} &lt;\/script&gt; It looks like this when rendered\nThe mode=display makes it so that it is centered in case that is what you need because it looks better than left or right aligned.\nThe rest of the markup is taken from (Tex)[http:\/\/meta.math.stackexchange.com\/questions\/5020\/mathjax-basic-tutorial-and-quick-reference].\n","permalink":"https:\/\/generalzero.org\/posts\/2014\/03\/mathjax-with-toto\/","summary":"<p>This is how I make Toto embed MathJax in to the page using Tex markup.<\/p>\n<pre><code>&lt;script type=&quot;math\/tex; mode=display&quot;&gt;\n\\begin{align}\nx &amp;= 100011_2 \\\\\n  &amp;= 100_2 * 2^3 + 011_2 \n\\end{align}\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>It looks like this when rendered<\/p>\n<script type=\"math\/tex; mode=display\">\n\\begin{align}\nx &= 100011_2 \\\\\n  &= 100_2 * 2^3 + 011_2 \n\\end{align}\n<\/script>\n<p>The <code>mode=display<\/code> makes it so that it is centered in case that is what you need because it looks better than left or right aligned.<\/p>","title":"MathJax With Toto"},{"content":"I recently looked at a amazing peice of simple mathmatics called Karatsuba&rsquo;s Multiplication. The orignal article went in depth proving that it does infact decrease the ammount of expencive opetation when multiplying numbers together.\nThis was an intristing descovery and when I though about it further I beleve that I can make it even faster than that in terms of a computer.\nI will take his basic condition and improve on it\nAssuming that the Base (B) is 2. We convert it in to\nIn doing so we convert simplify the power. If a number is raised to a power of 2 than it is just doing a binary shift.\nNow you get:\nNow lets break down X in to its parts.\nAnd the same for Y.\nLets compute A\nAnd C.\nAnd finaly B\nAnd plugging it back in\n","permalink":"https:\/\/generalzero.org\/posts\/2014\/02\/binary-karatsuba\/","summary":"<p>I recently looked at a amazing peice of simple mathmatics called Karatsuba&rsquo;s Multiplication. The <a href=\"http:\/\/www.stoimen.com\/blog\/2012\/05\/15\/computer-algorithms-karatsuba-fast-multiplication\/\">orignal article<\/a> went in depth proving that it does infact decrease the ammount of expencive opetation when multiplying numbers together.<\/p>\n<p>This was an intristing descovery and when I though about it further I beleve that I can make it even faster than that in terms of a computer.<\/p>\n<p>I will take his basic condition and improve on it<\/p>","title":"Binary Karatsuba Multiplication"},{"content":"Toto seems that its a blogging engine but there are a few things that still need to be worked out. I hear that it works great in Heroku but it doesn&rsquo;t seem to work so well in your own server. The routes to the file are a little bit buggy but you can fix that as long as you make the file name\n%Y-%m-%d-{:slug}.{:ext}\nMake sure that you specify some of these in the config\nset :author, &quot;GeneralZer0&quot; set :title, &quot;GeneralZer0 Blog&quot; set :root, &quot;index&quot; set :date, lambda {|now| now.strftime(&quot;%d\/%m\/%Y&quot;) } set :markdown, :smart set :summary, :max =&gt; 150, :delim =&gt; \/~\/ set :ext, 'txt' Remember these are only the defaults. The interesting part of toto is that you can put variables in the file its self so lets have a look at a file\ntitle: It is alive author: GeneralZer0 slug: blog-up date: %Y\/%m\/%d Insert test here Here is a great guide to alot of information\n","permalink":"https:\/\/generalzero.org\/posts\/2013\/10\/getting-toto-working-on-a-server-non-heroku\/","summary":"<p>Toto seems that its a blogging engine but there are a few things that still need to be worked out. I hear that it works great in Heroku but it doesn&rsquo;t seem to work so well in your own server. The routes to the file are a little bit buggy but you can fix that as long as you make the file name<\/p>\n<p><code>%Y-%m-%d-{:slug}.{:ext}<\/code><\/p>\n<p>Make sure that you specify some of these in the config<\/p>","title":"Getting TOTO working on a Server (non Heroku)"},{"content":"Finishing up my config for nginx with a proxy for php and rails will update soon with the final config.\n","permalink":"https:\/\/generalzero.org\/posts\/2013\/10\/configuring-nginx-with-rails-and-php-together\/","summary":"<p>Finishing up my config for nginx with a proxy for php and rails will update soon with the final config.<\/p>","title":"Configuring Nginx with Rails and PHP Together"}]