├── ECDH.md
├── Golomb-Compressed-Sets.md
├── PROCEDURE.MD
├── README.md
├── paillier_cryptosystem.md
├── Block-Sizes.md
├── Encryption-Key-Sizes.md
├── RC5.py
├── brute-force-attack.md
├── rc4.md
├── RC2.md
├── Threefish.md
├── mars.md
├── Twofish.md
├── part1.md
├── RC6.md
├── Blowfish.md
├── Symmetric-Key-Algorithms.md
├── intro.md
├── Diffie-Hellman.md
├── IDEA.md
├── RSA.md
├── Serpent.md
├── DES.md
├── AES.md
├── hashlib starts.ipynb
├── Elliptic Curve
├── crypten(addition).ipynb
├── LICENSE
├── crypten(binary_secret_sharing_).ipynb
└── crypten(secret_sharing_).ipynb
/ECDH.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Golomb-Compressed-Sets.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/PROCEDURE.MD:
--------------------------------------------------------------------------------
1 | # PROCEDURE
2 | 1. Encode (fixed precision)
3 | 2. Encrypt
4 | 3. Arithmetic
5 | 4. Decrypt
6 | 5. Decode
7 |
8 |
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # INTRODUCTION-TO-CRYPTOGRAPHY
2 |
3 | Bonjour, mon ami
4 |
5 |
6 | Bienvenue dans mes notes cryptographiques
7 |
8 | # will add more things soon(private -> public)
9 |
--------------------------------------------------------------------------------
/paillier_cryptosystem.md:
--------------------------------------------------------------------------------
1 | # PAILLIER CRYPTOSYSTEM
2 | KEY GENERATION
3 | 1) P,Q -> TWO PRIME NUMBERS WHEN GCD(P*Q, (P-1)(Q-1)) = 1
4 | # THIS STEP 1 WORKS IF P AND Q ARE PRIME OF EQUAL LENGTH.
5 | 2)Calculate N = P*Q AND LCM (P-1,Q-1)
6 | 3)SELECT G AS G BELONGS TO INTEGER WHICH VARIES TO N^2
7 |
--------------------------------------------------------------------------------
/Block-Sizes.md:
--------------------------------------------------------------------------------
1 | Some algorithms use “block ciphers”, which encrypt and decrypt data in blocks (fixed length groups of bits). There is a relationship between block size and the amount of data that can be encrypted without duplicating blocks, the explanation of which is beyond the scope of this post, but the key takeaway is that the current recommendation is to use at least 128 bit blocks.
2 |
--------------------------------------------------------------------------------
/Encryption-Key-Sizes.md:
--------------------------------------------------------------------------------
1 | Encryption Key Sizes
2 |
3 | Key size or key length refers to the number of bits in a key used by a cryptographic algorithm. Only the correct key can decrypt a ciphertext (output) back into plaintext (input). As CPU power gets more advanced, the computational time required to brute force an encryption key gets less and less. As such, keys have had to become longer. For many years the limit was 40-bits, but today we are seeing up to 4096-bit key lengths in cryptography.
4 |
--------------------------------------------------------------------------------
/RC5.py:
--------------------------------------------------------------------------------
1 | RC5
2 |
3 | Ron Rivest designed RC5 in 1994 to be variable on all fronts. Block sizes can vary from 32, 64 or 128 bits and key sizes from 0-2040 bits and rounds from 0-255. The original suggestion for parameters was 64-bit block, 128-bit key and 12 rounds.
4 |
5 | In Use Today? – Distributed.net are working on brute-force attacks on RC5. They have cracked the 56-bit key in 250 days and the 64-bit key in 1,757 days. They are still working on the 72-bit key, arguably still making it safe to use.
6 |
--------------------------------------------------------------------------------
/brute-force-attack.md:
--------------------------------------------------------------------------------
1 | Brute Force Attack
2 |
3 | A brute force attack or a dictionary attack as it’s also known is a trial and error method of obtaining the private key of an encrypted packet of data. The trial and error is done by a computer so the higher the computational power, the more “tries” it can have in a short space of time. As computing power and performance increases, the ability to find the private key increases, unless you increase the length of the key so that a higher number of possibilities exist.
4 |
--------------------------------------------------------------------------------
/rc4.md:
--------------------------------------------------------------------------------
1 | RC4
2 |
3 | RC4 was designed by Ron Rivest in 1987 initially as a trade secret until it was posted in the Cypherpunks mailing list in 1994. Once it got out to the sci-crypt newsgroup, it was quickly broken by Bob Jenkins. The algorithm has never been officially released by RSA Security but it has been used in some encryption protocols and standards such as WEP in 1997, WPA in 2003, SSL in 1995 and TLS in 1999 until it was prohibited in all versions of TLS RFC 7465 in 2015.
4 |
5 | In Use Today? – No. Recommended that this is not used.
6 |
--------------------------------------------------------------------------------
/RC2.md:
--------------------------------------------------------------------------------
1 | RC 2
2 |
3 | Rivest’s cipher, Ron’s code or, more commonly, RC algorithms were invented by Ron Rivest. While they share the same family name, the algorithms are quite different. For the purposes of this article, we will separate the names out.
4 |
5 | Starting with RC2, which Ron Rivest created in 1987, is a 64-bit block cipher with variable key sizes and 18 rounds, arranged as a heavy unbalanced Feistel network (16 rounds on one type and two rounds on another).
6 |
7 | In Use Today? – No. Recommended that this is not used. It is vulnerable to a related-key attack using 234 chosen plaintexts.
8 |
--------------------------------------------------------------------------------
/Threefish.md:
--------------------------------------------------------------------------------
1 | Threefish
2 |
3 | Threefish worked on 256-bit, 512-bit and 1024-bit blocks with the same key sizes as the block and up to 80 rounds. Threefish was created in 2008 as part of the Skein Hash Function, one of five finalists of the NIST’s SHA-3 hash function competition. Threefish was heralded for its speed; Threefish-512 can encrypt data at 6.1 block cycles per byte on a 64-bit machine.
4 |
5 | In Use Today? – Yes. Still available to use patent-free. However, in October 2010, an attack was published that could break 53 of 72 rounds in Threefish-256 and 57 of 72 rounds in Threefish-512, so it could still be risky to use Threefish.
6 |
--------------------------------------------------------------------------------
/mars.md:
--------------------------------------------------------------------------------
1 | MARS
2 |
3 | After DES was found to be weak, NIST ran an open call process known as the Advanced Encryption Standard Process from 1997 to 2000 to find a new and improved block cipher. MARS was one of the finalists, making it far for its layered, compartmentalized approach aimed at resisting future advances in cryptography and CPU power.
4 |
5 | MARS supports 128-bit blocks and variable key sizes on a number of core and mixed rounds providing strong resistance to cryptographic attack. Critics suggested that subkeys with long runs of ones and zeroes may have led to an easy and effective attack on MARS.
6 |
7 | In Use Today? – No. 21 of 23 rounds of MARS were broken by Bruce Schneier and John Kelsey in 2004.
8 |
--------------------------------------------------------------------------------
/Twofish.md:
--------------------------------------------------------------------------------
1 | Twofish
2 |
3 | Twofish is Blowfish’s successor published in 1998. With a block size of 128-bits, key sizes up to 256-bits and 16 rounds, it became one of the five finalists of the Advanced Encryption Standard competition but was not selected for standardization. It was a step up from Blowfish in that it could be implemented on hardware and smartcards as well as large microprocessors.
4 |
5 | Bruce Schneier and the team that created Twofish offered a $10,000 prize for anyone who could attack it during its first round of AES evaluation. In 1999, Sean Murphy and Fauzan Mirza won the prize for their paper, ‘An Observation on the Key Schedule of Twofish’.
6 |
7 | In Use Today? – Yes. Still available to use patent-free.
8 |
--------------------------------------------------------------------------------
/part1.md:
--------------------------------------------------------------------------------
1 | # SMPC
2 | 1. multiple workers --> remote parties --> TRUSTED AGGREGATOR(Provides Encryption)
3 |
4 | 2. In order to decrypt a value all of the workers must agree to put it back together.
5 |
6 | 3. values are split into shares which are distributed amongst the workers.
7 |
8 | 4. Values are split into shares which are distributed amongst workers.
9 |
10 |
11 | # MAJOR DIFFERENCE BETWEEN "MPC" and "HE"
12 | At a high level HE is often replaceable by MPC, and vice versa. HE requiring little interaction but expensive computation, whereas MPC uses cheap computation but a significant amount of interaction. Or in other words, MPC replaces expensive computation with interaction between two or more parties.
13 |
--------------------------------------------------------------------------------
/RC6.md:
--------------------------------------------------------------------------------
1 | RC6
2 |
3 | RC6 was derived from RC5 by Ron Rivest and colleagues. It was designed to meet the requirements of the Advanced Encryption Standard competition and managed to become one of the five finalists. It has a block size of 128-bits and supported key sizes of 128, 192, 256-bits and up to 2040-bits. RC6, like RC5, uses data-dependent rotations, modular addition and XOR operations. The algorithm was not chosen because the RSA Security website suggested that the algorithm was not yet royalty free.
4 |
5 | In Use Today? – Leaked files from the NSA suggest that it was used in implant devices in 2016. Other than this, it looks like RC6 might still hold two patents in the US: US 5724428 A and US 5835600 A but the patents are set to expire between 2015-2017.
6 |
--------------------------------------------------------------------------------
/Blowfish.md:
--------------------------------------------------------------------------------
1 | Blowfish
2 |
3 | Blowfish is a symmetric block cipher built by Bruce Schneier as a replacement to DES and IDEA. It takes variable key sizes from 32-bits to 448-bits, 64-bit block size and 16-rounds and was one of the first unpatented and license free block cipher (and still is). Serge Vaudenay, the French cryptographer found a way to use weak keys in a plaintext attack to recover 14 of the 16 rounds.
4 |
5 | Blowfish has also been criticized for being slow in certain applications and vulnerable to Birthday Attacks in HTTPS.
6 |
7 | In Use Today? – No. While, it’s now know to be vulnerable to Sweet32 attack, birthday attacks and plaintext attacks, some applications are still using it, for example to encrypt passwords. Bruce Schneier now recommends the use of Twofish.
8 |
--------------------------------------------------------------------------------
/Symmetric-Key-Algorithms.md:
--------------------------------------------------------------------------------
1 | Symmetric Key Algorithms
2 |
3 | symmetric algorithms
4 |
5 | A symmetric key algorithm (also known as a secret key algorithm), uses the concept of a key and lock to encrypt plaintext and decrypt ciphertext data. The same “key” is used to both encrypt and decrypt the file. They are sub-classified by stream ciphers and block ciphers. A stream cipher is where plaintext digits are combined with a pseudo-random cipher digit stream. Block ciphers take the number of bits and encrypt them as a single unit (known as rounds), padding the plaintext so that it’s a multiple of a block size.
6 |
7 | The algorithm itself is not kept a secret and the sender and receiver of communication must both have copies of the secret key in a secure place. The use of the same key is also one of the drawbacks of symmetric key cryptography because if someone can get hold of the key, they can decrypt your data.
8 |
--------------------------------------------------------------------------------
/intro.md:
--------------------------------------------------------------------------------
1 | Cryptography at its very core is math. Pure, simple, undiluted math. Math created the algorithms that are the basis for all encryption. And encryption is the basis for privacy and security on the internet. So, we love math. Even if it is a tad complicated. With that being said, algorithms have to be built to work against computers. As computers get smarter, algorithms become weaker and we must therefore look at new solutions. This is how cryptography evolves to beat the bad guys.
2 |
3 | So how is it done? First you need to build a cryptosystem that is both confidential and authentic. This cryptosystem is responsible for creating the key(s) that will be used to encrypt and then decrypt the data or message. A number of signing algorithms have been created over the years to create these keys, some of which have since been deprecated as computing power has increased.
4 |
5 | Before going through some of the main and most popular algorithms known in cryptography, it might be a good idea to recap on a couple of terms you will probably come across a lot during this article.
6 |
--------------------------------------------------------------------------------
/Diffie-Hellman.md:
--------------------------------------------------------------------------------
1 | Diffie-Hellman
2 |
3 | Diffie-Hellman is one of the first recorded examples of asymmetric cryptography, first conceptualized by Ralph Merkle and put into fruition by Whitfield Diffie and Martin Hellman. Traditionally, secure encrypted communication would require both parties to first exchange their keys by some secure physical channel. Diffie-Hellman eliminated the need for the secure exchange by creating an additional key, the public key.
4 |
5 | At this moment in time, Deffie-Hellman is no longer the standard cryptographic algorithm because it has been found to be vulnerable to several attacks. A Logjam attack, for example, can allow man-in-the-middle attacks where the hacker can read and modify any data sent over the connection.
6 |
7 | In Use Today? – Yes. For general PKI security and digital signing, NIST recommends RSA (see below) because Diffie-Hellman requires more CPU power and larger data exchange for Digital Signing and SSL in particular. But there are still some uses of Diffie-Hellman in the public sphere today for example, in Elliptic Curve Cryptography
8 |
--------------------------------------------------------------------------------
/IDEA.md:
--------------------------------------------------------------------------------
1 | The International Data Encryption Algorithm (IDEA), originally called the Improved Proposed Encryption Standard (IPES), was designed by James Massey of ETH Zurich under a research contract with the Hasler Foundation, now Ascom Tech AG ,and was first discussed in 1991. IDEA was a minor revision of the Proposed Encryption Standard (PES), intended as a replacement of the DES.
2 |
3 | IDEA is now patent-free and thus completely free for all uses, but the name itself is still trademarked. It operated on a 64-bit block using 128-bit key and is still an optional algorithm in the OpenPGP standard. Bruce Schneier spoke highly of this algorithm in 1996 until such a time as the patents became difficult to put it into use and the speed of the algorithm couldn’t keep up with modern technology.
4 |
5 | IDEA’s full 8.5 round algorithm was first broken in 2011 using a meet-in-the-middle attack and independently in 2012 using a narrow-bicliques attack. In May 2005, MediaCrypt announced a successor of IDEA called IDEA NXT.
6 |
7 | In Use Today? – Not widely used, but is now patent-free to use in applications of your choice.
8 |
--------------------------------------------------------------------------------
/RSA.md:
--------------------------------------------------------------------------------
1 | RSA
2 |
3 | The Rivest-Shammir-Adleman algorithm, better known as RSA, is now the most widely used asymmetric cryptosystem on the web today. RSA is based on the factorization of prime numbers, because working backwards from two multiplied prime numbers is computationally difficult to do, more so as the prime numbers get larger. The challenge of breaking RSA is known as the ‘RSA problem’.
4 |
5 | RSA is a slow algorithm and because of this, it is used to encrypt and decrypt the symmetric keys which in turn, encrypt and decrypt the communications. The symmetric keys perform the bulk of the work, while RSA creates a strong and secure channel.
6 |
7 | In 1998, Daniel Bleichenbacher described how he exploited a vulnerability in the PKCS#1 file (used to carry the private key). His attack was able to retrieve the private key and use it to recover session keys and decrypt messages. As a result of his work, RSA Laboratories released new versions of PKCS#1 that are not vulnerable to the same attack. While some attacks to RSA have been attempted, the algorithm remains strong, arguably until quantum computers become mainstream.
8 |
9 | In Use Today? – Yes. RSA is the most widely used asymmetric algorithm today.
10 |
--------------------------------------------------------------------------------
/Serpent.md:
--------------------------------------------------------------------------------
1 | Serpent
2 |
3 | Serpent was also entered into the Advanced Encryption Standard competition and was actually ranked second to Rijndael (now known as AES). Serpent was designed in 1998 by Ross Anderson, Eli Buham and Lars Knudsen. It has a block size of 128-bits, 192 or 256-bits with a block length of 128-bits and 32 rounds. Rijndael won over Serpent because judges deemed that it has more efficient software implementations.
4 |
5 | In 2001, Eli Burham alongside Orr Dunkelman and Nathan Keller were able to break 10 of 32 rounds of Serpent-128 with 2118 known plaintexts and 289 of time. They could also break Serpent-192/256 with 2118 plaintext and 2187 time. Other papers have since come closer, breaking up to 12 rounds but still not close enough to consider the algorithm weak.
6 |
7 | In Use Today? – Yes. Serpent is still in the public domain and while some attacks have managed to get through up to 12 rounds of the full 32, the time and energy needed for such an attack is still quite large.
8 | Asymmetric Algorithms
9 |
10 | asymmetric algorithms
11 |
12 | Asymmetric cryptography is also known as public key cryptography and is based on the principle of having a pair of mathematically-related keys for encryption and decryption: a public key and a private key. The public key pair can be shared with anyone, while the private key must be kept secret. Anyone with the public key can encrypt a message but only the holder of a private key can decrypt it. Security depends on the secrecy of the private keys.
13 |
--------------------------------------------------------------------------------
/DES.md:
--------------------------------------------------------------------------------
1 | DES
2 |
3 | The Data Encryption Standard or DES was, and probably still is, one of the more well-known algorithms of the modern cryptographic era. Today it is widely considered insecure. DES was developed in the 1970’s by IBM and was later submitted to the National Bureau of Standards (NBS) and National Security Agency (NSA). The involvement of the NSA in the design sparked controversial rumours of backdoors, creating widespread scrutiny. It wasn’t until 1976 that DES was approved as a cryptographic standard and published in FIPS.
4 |
5 | In the 1990’s, computing 72 quadrillion possible keys for a 56 bit DES key seemed highly improbable. This would have been true for one computer, but in 1997 a group of computer scientists led by Rocke Verser used thousands of volunteer computers to crack DES within 24 hours, thereby making him and his team the winner of the $10,000 DES Challenge.
6 |
7 | Since then, DES was fortified with new updates called double-DES and triple-DES, simply layering the cipher so that it would have to decrypt three times to each data block. Triple-DES is still used in some places, but AES (see below) has become the new standard since then.
8 |
9 | In Use Today? – DES and double-DES are no longer in use, but triple-DES with three keys is still a recommended algorithm in NIST SP 800-57. It is much slower to use than the AES algorithm, but is still seen in the electronic payment industry. It is also used in Microsoft OneNote and Outlook 2007 to protect user content and system data and the browsers Firefox and Mozilla Thunderbird in CBC mode to encrypt website authentication login credentials when using a master password.
10 |
--------------------------------------------------------------------------------
/AES.md:
--------------------------------------------------------------------------------
1 | AES
2 |
3 | The Advanced Encryption Standard or AES
4 |
5 | features of aes
6 | ## symmetric key cipher
7 | ## 128 bit data
8 |
9 |
10 | 1) iterative method
11 | 2) based on 'substitution-permutation network'
12 |
13 | ## ENCRYPTION PROCESS
14 | Byte Substitution (SubBytes)
15 |
16 | The 16 input bytes are substituted by looking up a fixed table (S-box) given in design. The result is in a matrix of four rows and four columns.
17 | Shiftrows
18 |
19 | Each of the four rows of the matrix is shifted to the left. Any entries that ‘fall off’ are re-inserted on the right side of row. Shift is carried out as follows −
20 |
21 | First row is not shifted.
22 |
23 | Second row is shifted one (byte) position to the left.
24 |
25 | Third row is shifted two positions to the left.
26 |
27 | Fourth row is shifted three positions to the left.
28 |
29 | The result is a new matrix consisting of the same 16 bytes but shifted with respect to each other.
30 |
31 | MixColumns
32 |
33 | Each column of four bytes is now transformed using a special mathematical function. This function takes as input the four bytes of one column and outputs four completely new bytes, which replace the original column. The result is another new matrix consisting of 16 new bytes. It should be noted that this step is not performed in the last round.
34 | Addroundkey
35 |
36 | The 16 bytes of the matrix are now considered as 128 bits and are XORed to the 128 bits of the round key. If this is the last round then the output is the ciphertext. Otherwise, the resulting 128 bits are interpreted as 16 bytes and we begin another similar round.
37 |
38 |
39 |
40 | ## Decryption Process
41 |
42 | The process of decryption of an AES ciphertext is similar to the encryption process in the reverse order. Each round consists of the four processes conducted in the reverse order −
43 |
44 | Add round key
45 | Mix columns
46 | Shift rows
47 | Byte substitution
48 |
49 | Since sub-processes in each round are in reverse manner, unlike for a Feistel Cipher, the encryption and decryption algorithms needs to be separately implemented, although they are very closely related.
50 |
--------------------------------------------------------------------------------
/hashlib starts.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "metadata": {},
7 | "outputs": [
8 | {
9 | "name": "stdout",
10 | "output_type": "stream",
11 | "text": [
12 | "{'sha3_384', 'sha512-224', 'md5', 'sha3-512', 'sha384', 'shake256', 'sha3_512', 'sha3_224', 'sha512-256', 'sha3_256', 'blake2b512', 'ripemd160', 'shake_128', 'sha3-384', 'sha3-224', 'sha512', 'shake_256', 'sha224', 'sha256', 'blake2b', 'blake2s256', 'md5-sha1', 'shake128', 'whirlpool', 'sm3', 'sha1', 'md4', 'blake2s', 'sha3-256', 'mdc2'}\n",
13 | "{'sha512', 'sha3_384', 'sha3_512', 'shake_256', 'sha224', 'sha3_224', 'sha256', 'blake2b', 'sha3_256', 'sha1', 'md5', 'shake_128', 'blake2s', 'sha384'}\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "\n",
19 | "import hashlib\n",
20 | "\n",
21 | "print(hashlib.algorithms_available)\n",
22 | "print(hashlib.algorithms_guaranteed)\n",
23 | "\n"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": 4,
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "name": "stdout",
33 | "output_type": "stream",
34 | "text": [
35 | "HASHING 256 BE LIKE : b'\\xees/\\x13\\xb7\\x04\\xa5U\\xf1\\x88\\xa5m$j\\xa1~\\\\9\\xd2\\xba0\\xfb~\\xbbQ\\x81\\xae\\xc3\\x82o#\\xf0'\n"
36 | ]
37 | }
38 | ],
39 | "source": [
40 | "x = hashlib.sha256()\n",
41 | "#THIS IS JUST TRYING SHA256\n",
42 | "x.update(b\"YO GOOGLE SUCKS BRO\")\n",
43 | "print('HASHING 256 BE LIKE :', x.digest())"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": null,
49 | "metadata": {},
50 | "outputs": [],
51 | "source": []
52 | }
53 | ],
54 | "metadata": {
55 | "kernelspec": {
56 | "display_name": "Python 3",
57 | "language": "python",
58 | "name": "python3"
59 | },
60 | "language_info": {
61 | "codemirror_mode": {
62 | "name": "ipython",
63 | "version": 3
64 | },
65 | "file_extension": ".py",
66 | "mimetype": "text/x-python",
67 | "name": "python",
68 | "nbconvert_exporter": "python",
69 | "pygments_lexer": "ipython3",
70 | "version": "3.7.4"
71 | }
72 | },
73 | "nbformat": 4,
74 | "nbformat_minor": 2
75 | }
76 |
--------------------------------------------------------------------------------
/Elliptic Curve:
--------------------------------------------------------------------------------
1 | Elliptic Curve
2 |
3 | ECC stands for Elliptic Curve Cryptography, which is an approach to public key cryptography based on elliptic curves over finite fields. Cryptographic algorithms usually use a mathematical equation to decipher keys; ECC, while still using an equation, takes a different approach.
4 |
5 | SSL/TLS Certificates most commonly use RSA keys and the recommended size of these keys keeps increasing (e.g. from 1024 bit to 2048 bit a few years ago) to maintain sufficient cryptographic strength. An alternative to RSA is ECC. Both key types share the same important property of being asymmetric algorithms (one key for encrypting and one key for decrypting). However, ECC can offer the same level of cryptographic strength at much smaller key sizes - offering improved security with reduced computational and storage requirements.
6 |
7 | In Use Today? - Yes. NIST has recommended 15 elliptic curves that can be used as standard. Some argue that it is weak because vulnerabilities have been found that allow an attacker to execute certain types of attack although there are ways to combat these. Other reasons for a lack in popularity are to do with the random key generator created by NIST, dubbed Dual Elliptic Curve Deterministic Random Bit Generator or DUAL_EC_DRBG for short. Some believed that the generator (developed by the NSA) wasn’t as random as you might think – it was later discontinued.
8 | It’s All Math
9 |
10 | As quantum computing comes hurtling towards us, many wonder what cryptography will be like. Some argue that our traditional approach of increasing key size to combat increased computing power will hit its limit. Others think that might not necessarily be the case.
11 |
12 | If there’s anything to take away from this, it’s that algorithms all have a “margin of safety” as Bruce Schneier put it. We must recognise that with enough computing power and time, it is possible to break an algorithm, but if we continue to work together and stay on top of computational performance, we can find new algorithms to replace the old ones.
13 |
14 | If you think we’ve missed an algorithm in this post, feel free to tell us and we would be happy to include it. Keep your eyes peeled for a follow up blog on cryptographic hash functions including SHA and MD.
15 |
--------------------------------------------------------------------------------
/crypten(addition).ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "crypten(addition).ipynb",
7 | "provenance": [],
8 | "authorship_tag": "ABX9TyPpzHEby5lgx1Hzby6XFp7u",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | }
15 | },
16 | "cells": [
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "view-in-github",
21 | "colab_type": "text"
22 | },
23 | "source": [
24 | "
"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "metadata": {
30 | "id": "LHczWe-DdQa7",
31 | "colab_type": "code",
32 | "colab": {
33 | "base_uri": "https://localhost:8080/",
34 | "height": 917
35 | },
36 | "outputId": "85c9d61e-740e-4bf7-bb42-8a96dc49554d"
37 | },
38 | "source": [
39 | "!pip install crypten"
40 | ],
41 | "execution_count": 1,
42 | "outputs": [
43 | {
44 | "output_type": "stream",
45 | "text": [
46 | "Collecting crypten\n",
47 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/19/6a/008b0935bc28eea0d1b80a8e967117bf5975c2c259d4b864ec25307308a5/crypten-0.1-py3-none-any.whl (148kB)\n",
48 | "\u001b[K |████████████████████████████████| 153kB 2.8MB/s \n",
49 | "\u001b[?25hCollecting onnx\n",
50 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/36/ee/bc7bc88fc8449266add978627e90c363069211584b937fd867b0ccc59f09/onnx-1.7.0-cp36-cp36m-manylinux1_x86_64.whl (7.4MB)\n",
51 | "\u001b[K |████████████████████████████████| 7.4MB 8.1MB/s \n",
52 | "\u001b[?25hCollecting torch==1.4.0\n",
53 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/24/19/4804aea17cd136f1705a5e98a00618cb8f6ccc375ad8bfa437408e09d058/torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (753.4MB)\n",
54 | "\u001b[K |████████████████████████████████| 753.4MB 21kB/s \n",
55 | "\u001b[?25hCollecting torchvision==0.5.0\n",
56 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/7e/90/6141bf41f5655c78e24f40f710fdd4f8a8aff6c8b7c6f0328240f649bdbe/torchvision-0.5.0-cp36-cp36m-manylinux1_x86_64.whl (4.0MB)\n",
57 | "\u001b[K |████████████████████████████████| 4.0MB 36.6MB/s \n",
58 | "\u001b[?25hRequirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from crypten) (0.16.0)\n",
59 | "Requirement already satisfied: tensorboard in /usr/local/lib/python3.6/dist-packages (from crypten) (2.3.0)\n",
60 | "Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (1.15.0)\n",
61 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (1.18.5)\n",
62 | "Requirement already satisfied: protobuf in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (3.12.4)\n",
63 | "Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (3.7.4.2)\n",
64 | "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision==0.5.0->crypten) (7.0.0)\n",
65 | "Requirement already satisfied: grpcio>=1.24.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.30.0)\n",
66 | "Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (2.23.0)\n",
67 | "Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.9.0)\n",
68 | "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.0.1)\n",
69 | "Requirement already satisfied: wheel>=0.26; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.34.2)\n",
70 | "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (3.2.2)\n",
71 | "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.7.0)\n",
72 | "Requirement already satisfied: google-auth<2,>=1.6.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.17.2)\n",
73 | "Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (49.2.0)\n",
74 | "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.4.1)\n",
75 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (2020.6.20)\n",
76 | "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (3.0.4)\n",
77 | "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (1.24.3)\n",
78 | "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (2.10)\n",
79 | "Requirement already satisfied: importlib-metadata; python_version < \"3.8\" in /usr/local/lib/python3.6/dist-packages (from markdown>=2.6.8->tensorboard->crypten) (1.7.0)\n",
80 | "Requirement already satisfied: rsa<5,>=3.1.4; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (4.6)\n",
81 | "Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (4.1.1)\n",
82 | "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (0.2.8)\n",
83 | "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard->crypten) (1.3.0)\n",
84 | "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata; python_version < \"3.8\"->markdown>=2.6.8->tensorboard->crypten) (3.1.0)\n",
85 | "Requirement already satisfied: pyasn1>=0.1.3 in /usr/local/lib/python3.6/dist-packages (from rsa<5,>=3.1.4; python_version >= \"3\"->google-auth<2,>=1.6.3->tensorboard->crypten) (0.4.8)\n",
86 | "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.6/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard->crypten) (3.1.0)\n",
87 | "Installing collected packages: onnx, torch, torchvision, crypten\n",
88 | " Found existing installation: torch 1.6.0+cu101\n",
89 | " Uninstalling torch-1.6.0+cu101:\n",
90 | " Successfully uninstalled torch-1.6.0+cu101\n",
91 | " Found existing installation: torchvision 0.7.0+cu101\n",
92 | " Uninstalling torchvision-0.7.0+cu101:\n",
93 | " Successfully uninstalled torchvision-0.7.0+cu101\n",
94 | "Successfully installed crypten-0.1 onnx-1.7.0 torch-1.4.0 torchvision-0.5.0\n"
95 | ],
96 | "name": "stdout"
97 | }
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "metadata": {
103 | "id": "3V8giUdvdZDZ",
104 | "colab_type": "code",
105 | "colab": {}
106 | },
107 | "source": [
108 | "import torch\n",
109 | "import crypten"
110 | ],
111 | "execution_count": 2,
112 | "outputs": []
113 | },
114 | {
115 | "cell_type": "code",
116 | "metadata": {
117 | "id": "owu_OLffdZGv",
118 | "colab_type": "code",
119 | "colab": {}
120 | },
121 | "source": [
122 | "crypten.init()\n"
123 | ],
124 | "execution_count": 3,
125 | "outputs": []
126 | },
127 | {
128 | "cell_type": "code",
129 | "metadata": {
130 | "id": "Hb4kA91BdZJd",
131 | "colab_type": "code",
132 | "colab": {}
133 | },
134 | "source": [
135 | "x = torch.tensor([1.0, 2.0, 3.0])\n",
136 | "x_enc = crypten.cryptensor(x) # encrypt\n",
137 | "\n"
138 | ],
139 | "execution_count": 4,
140 | "outputs": []
141 | },
142 | {
143 | "cell_type": "code",
144 | "metadata": {
145 | "id": "KoIJ0P3rdZMK",
146 | "colab_type": "code",
147 | "colab": {}
148 | },
149 | "source": [
150 | "x_dec = x_enc.get_plain_text() # decrypt\n"
151 | ],
152 | "execution_count": 5,
153 | "outputs": []
154 | },
155 | {
156 | "cell_type": "code",
157 | "metadata": {
158 | "id": "ueGHpoTzdZOs",
159 | "colab_type": "code",
160 | "colab": {}
161 | },
162 | "source": [
163 | "\n",
164 | "y_enc = crypten.cryptensor([2.0, 3.0, 4.0])\n"
165 | ],
166 | "execution_count": 6,
167 | "outputs": []
168 | },
169 | {
170 | "cell_type": "code",
171 | "metadata": {
172 | "id": "ibs-QluDdZRl",
173 | "colab_type": "code",
174 | "colab": {}
175 | },
176 | "source": [
177 | "sum_xy = x_enc + y_enc # add encrypted tensors\n",
178 | "sum_xy_dec = sum_xy.get_plain_text() # decrypt sum"
179 | ],
180 | "execution_count": 7,
181 | "outputs": []
182 | },
183 | {
184 | "cell_type": "code",
185 | "metadata": {
186 | "id": "9Ok9wwTMdZUH",
187 | "colab_type": "code",
188 | "colab": {
189 | "base_uri": "https://localhost:8080/",
190 | "height": 35
191 | },
192 | "outputId": "c2cd2bd7-1ffc-4bf0-cd77-0ad41e0b7360"
193 | },
194 | "source": [
195 | "sum_xy_dec"
196 | ],
197 | "execution_count": 8,
198 | "outputs": [
199 | {
200 | "output_type": "execute_result",
201 | "data": {
202 | "text/plain": [
203 | "tensor([3., 5., 7.])"
204 | ]
205 | },
206 | "metadata": {
207 | "tags": []
208 | },
209 | "execution_count": 8
210 | }
211 | ]
212 | },
213 | {
214 | "cell_type": "code",
215 | "metadata": {
216 | "id": "xMP6cnIOdZWz",
217 | "colab_type": "code",
218 | "colab": {}
219 | },
220 | "source": [
221 | ""
222 | ],
223 | "execution_count": null,
224 | "outputs": []
225 | },
226 | {
227 | "cell_type": "code",
228 | "metadata": {
229 | "id": "9yS3ndZHdZZc",
230 | "colab_type": "code",
231 | "colab": {}
232 | },
233 | "source": [
234 | ""
235 | ],
236 | "execution_count": null,
237 | "outputs": []
238 | },
239 | {
240 | "cell_type": "code",
241 | "metadata": {
242 | "id": "Rde1dZ2RdZcS",
243 | "colab_type": "code",
244 | "colab": {}
245 | },
246 | "source": [
247 | ""
248 | ],
249 | "execution_count": null,
250 | "outputs": []
251 | }
252 | ]
253 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/crypten(binary_secret_sharing_).ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "crypten(binary secret sharing ).ipynb",
7 | "provenance": [],
8 | "authorship_tag": "ABX9TyPNRopve1T3OrPviTZjtC+/",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | }
15 | },
16 | "cells": [
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "view-in-github",
21 | "colab_type": "text"
22 | },
23 | "source": [
24 | "
"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "metadata": {
30 | "id": "LHczWe-DdQa7",
31 | "colab_type": "code",
32 | "colab": {
33 | "base_uri": "https://localhost:8080/",
34 | "height": 944
35 | },
36 | "outputId": "a4ae9f98-6271-4519-98aa-67cd8daa666e"
37 | },
38 | "source": [
39 | "!pip install crypten"
40 | ],
41 | "execution_count": 1,
42 | "outputs": [
43 | {
44 | "output_type": "stream",
45 | "text": [
46 | "Collecting crypten\n",
47 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/19/6a/008b0935bc28eea0d1b80a8e967117bf5975c2c259d4b864ec25307308a5/crypten-0.1-py3-none-any.whl (148kB)\n",
48 | "\u001b[K |████████████████████████████████| 153kB 3.2MB/s \n",
49 | "\u001b[?25hRequirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from crypten) (0.16.0)\n",
50 | "Collecting torch==1.4.0\n",
51 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/24/19/4804aea17cd136f1705a5e98a00618cb8f6ccc375ad8bfa437408e09d058/torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (753.4MB)\n",
52 | "\u001b[K |████████████████████████████████| 753.4MB 23kB/s \n",
53 | "\u001b[?25hCollecting onnx\n",
54 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/36/ee/bc7bc88fc8449266add978627e90c363069211584b937fd867b0ccc59f09/onnx-1.7.0-cp36-cp36m-manylinux1_x86_64.whl (7.4MB)\n",
55 | "\u001b[K |████████████████████████████████| 7.4MB 13.1MB/s \n",
56 | "\u001b[?25hCollecting torchvision==0.5.0\n",
57 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/7e/90/6141bf41f5655c78e24f40f710fdd4f8a8aff6c8b7c6f0328240f649bdbe/torchvision-0.5.0-cp36-cp36m-manylinux1_x86_64.whl (4.0MB)\n",
58 | "\u001b[K |████████████████████████████████| 4.0MB 34.7MB/s \n",
59 | "\u001b[?25hRequirement already satisfied: tensorboard in /usr/local/lib/python3.6/dist-packages (from crypten) (2.3.0)\n",
60 | "Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (3.7.4.2)\n",
61 | "Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (1.15.0)\n",
62 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (1.18.5)\n",
63 | "Requirement already satisfied: protobuf in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (3.12.4)\n",
64 | "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision==0.5.0->crypten) (7.0.0)\n",
65 | "Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.9.0)\n",
66 | "Requirement already satisfied: grpcio>=1.24.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.30.0)\n",
67 | "Requirement already satisfied: wheel>=0.26; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.34.2)\n",
68 | "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.0.1)\n",
69 | "Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (2.23.0)\n",
70 | "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (3.2.2)\n",
71 | "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.7.0)\n",
72 | "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.4.1)\n",
73 | "Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (49.2.0)\n",
74 | "Requirement already satisfied: google-auth<2,>=1.6.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.17.2)\n",
75 | "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (1.24.3)\n",
76 | "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (3.0.4)\n",
77 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (2020.6.20)\n",
78 | "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (2.10)\n",
79 | "Requirement already satisfied: importlib-metadata; python_version < \"3.8\" in /usr/local/lib/python3.6/dist-packages (from markdown>=2.6.8->tensorboard->crypten) (1.7.0)\n",
80 | "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard->crypten) (1.3.0)\n",
81 | "Requirement already satisfied: rsa<5,>=3.1.4; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (4.6)\n",
82 | "Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (4.1.1)\n",
83 | "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (0.2.8)\n",
84 | "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata; python_version < \"3.8\"->markdown>=2.6.8->tensorboard->crypten) (3.1.0)\n",
85 | "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.6/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard->crypten) (3.1.0)\n",
86 | "Requirement already satisfied: pyasn1>=0.1.3 in /usr/local/lib/python3.6/dist-packages (from rsa<5,>=3.1.4; python_version >= \"3\"->google-auth<2,>=1.6.3->tensorboard->crypten) (0.4.8)\n",
87 | "Installing collected packages: torch, onnx, torchvision, crypten\n",
88 | " Found existing installation: torch 1.6.0+cu101\n",
89 | " Uninstalling torch-1.6.0+cu101:\n",
90 | " Successfully uninstalled torch-1.6.0+cu101\n",
91 | " Found existing installation: torchvision 0.7.0+cu101\n",
92 | " Uninstalling torchvision-0.7.0+cu101:\n",
93 | " Successfully uninstalled torchvision-0.7.0+cu101\n",
94 | "Successfully installed crypten-0.1 onnx-1.7.0 torch-1.4.0 torchvision-0.5.0\n"
95 | ],
96 | "name": "stdout"
97 | }
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "metadata": {
103 | "id": "3V8giUdvdZDZ",
104 | "colab_type": "code",
105 | "colab": {}
106 | },
107 | "source": [
108 | "import torch\n",
109 | "import crypten"
110 | ],
111 | "execution_count": 2,
112 | "outputs": []
113 | },
114 | {
115 | "cell_type": "code",
116 | "metadata": {
117 | "id": "owu_OLffdZGv",
118 | "colab_type": "code",
119 | "colab": {}
120 | },
121 | "source": [
122 | "crypten.init()\n"
123 | ],
124 | "execution_count": 3,
125 | "outputs": []
126 | },
127 | {
128 | "cell_type": "markdown",
129 | "metadata": {
130 | "id": "rbpPrQpXtzhi",
131 | "colab_type": "text"
132 | },
133 | "source": [
134 | "Binary secret-sharing\n",
135 | "\n",
136 | "secret-sharing implemented in CrypTen is binary or XOR secret-sharing. This type of secret-sharing allows greater efficiency in evaluating logical expressions.\n",
137 | "\n",
138 | "Let's look more closely at the crypten.binary ptype. Most of the logical operations implemented by CrypTensors are implemented using arithmetic secret sharing. We typically use this type of secret-sharing when we want to evaluate binary operators (i.e. ^ & | >> <<, etc.) or logical operations (like comparitors).\n",
139 | "\n",
140 | "Let's begin by creating a new CrypTensor using ptype=crypten.binary to enforce that the encryption is done via binary secret sharing. We can print values of each share to confirm that values are being encrypted properly, as we did for arithmetic secret-shares.\n",
141 | "\n",
142 | "(Note that an xor of the two _tensor attributes below is equal to an unscaled version of input.) "
143 | ]
144 | },
145 | {
146 | "cell_type": "code",
147 | "metadata": {
148 | "id": "Hb4kA91BdZJd",
149 | "colab_type": "code",
150 | "colab": {
151 | "base_uri": "https://localhost:8080/",
152 | "height": 239
153 | },
154 | "outputId": "ca44ab91-2731-426a-bc3b-2285be32928a"
155 | },
156 | "source": [
157 | "\n",
158 | "import crypten.mpc as mpc\n",
159 | "import crypten.communicator as comm \n",
160 | "\n",
161 | "@mpc.run_multiprocess(world_size=2)\n",
162 | "def examine_binary_shares():\n",
163 | " x_enc = crypten.cryptensor([2, 3], ptype=crypten.binary)\n",
164 | " \n",
165 | " rank = comm.get().get_rank()\n",
166 | " print(f\"Rank {rank}:\\n {x_enc}\")\n",
167 | " \n",
168 | "x = examine_binary_shares()\n",
169 | "\n"
170 | ],
171 | "execution_count": 7,
172 | "outputs": [
173 | {
174 | "output_type": "stream",
175 | "text": [
176 | "Rank 0:\n",
177 | " MPCTensor(\n",
178 | "\t_tensor=tensor([7460896676695636061, 8416235150248527900])\n",
179 | "\tplain_text=HIDDEN\n",
180 | "\tptype=ptype.binary\n",
181 | ")\n",
182 | "Rank 1:\n",
183 | " MPCTensor(\n",
184 | "\t_tensor=tensor([7460896676695636063, 8416235150248527903])\n",
185 | "\tplain_text=HIDDEN\n",
186 | "\tptype=ptype.binary\n",
187 | ")\n"
188 | ],
189 | "name": "stdout"
190 | }
191 | ]
192 | },
193 | {
194 | "cell_type": "markdown",
195 | "metadata": {
196 | "id": "TEYbP08Zua3s",
197 | "colab_type": "text"
198 | },
199 | "source": [
200 | "https://eprint.iacr.org/2018/746.pdf"
201 | ]
202 | },
203 | {
204 | "cell_type": "code",
205 | "metadata": {
206 | "id": "xMP6cnIOdZWz",
207 | "colab_type": "code",
208 | "colab": {}
209 | },
210 | "source": [
211 | ""
212 | ],
213 | "execution_count": null,
214 | "outputs": []
215 | },
216 | {
217 | "cell_type": "code",
218 | "metadata": {
219 | "id": "9yS3ndZHdZZc",
220 | "colab_type": "code",
221 | "colab": {}
222 | },
223 | "source": [
224 | ""
225 | ],
226 | "execution_count": null,
227 | "outputs": []
228 | },
229 | {
230 | "cell_type": "code",
231 | "metadata": {
232 | "id": "Rde1dZ2RdZcS",
233 | "colab_type": "code",
234 | "colab": {}
235 | },
236 | "source": [
237 | ""
238 | ],
239 | "execution_count": null,
240 | "outputs": []
241 | }
242 | ]
243 | }
--------------------------------------------------------------------------------
/crypten(secret_sharing_).ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "nbformat": 4,
3 | "nbformat_minor": 0,
4 | "metadata": {
5 | "colab": {
6 | "name": "crypten(secret sharing ).ipynb",
7 | "provenance": [],
8 | "authorship_tag": "ABX9TyPPQYQ89bruXdK2Bx32764+",
9 | "include_colab_link": true
10 | },
11 | "kernelspec": {
12 | "name": "python3",
13 | "display_name": "Python 3"
14 | }
15 | },
16 | "cells": [
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "id": "view-in-github",
21 | "colab_type": "text"
22 | },
23 | "source": [
24 | "
"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "metadata": {
30 | "id": "LHczWe-DdQa7",
31 | "colab_type": "code",
32 | "colab": {
33 | "base_uri": "https://localhost:8080/",
34 | "height": 944
35 | },
36 | "outputId": "a4ae9f98-6271-4519-98aa-67cd8daa666e"
37 | },
38 | "source": [
39 | "!pip install crypten"
40 | ],
41 | "execution_count": 1,
42 | "outputs": [
43 | {
44 | "output_type": "stream",
45 | "text": [
46 | "Collecting crypten\n",
47 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/19/6a/008b0935bc28eea0d1b80a8e967117bf5975c2c259d4b864ec25307308a5/crypten-0.1-py3-none-any.whl (148kB)\n",
48 | "\u001b[K |████████████████████████████████| 153kB 3.2MB/s \n",
49 | "\u001b[?25hRequirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from crypten) (0.16.0)\n",
50 | "Collecting torch==1.4.0\n",
51 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/24/19/4804aea17cd136f1705a5e98a00618cb8f6ccc375ad8bfa437408e09d058/torch-1.4.0-cp36-cp36m-manylinux1_x86_64.whl (753.4MB)\n",
52 | "\u001b[K |████████████████████████████████| 753.4MB 23kB/s \n",
53 | "\u001b[?25hCollecting onnx\n",
54 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/36/ee/bc7bc88fc8449266add978627e90c363069211584b937fd867b0ccc59f09/onnx-1.7.0-cp36-cp36m-manylinux1_x86_64.whl (7.4MB)\n",
55 | "\u001b[K |████████████████████████████████| 7.4MB 13.1MB/s \n",
56 | "\u001b[?25hCollecting torchvision==0.5.0\n",
57 | "\u001b[?25l Downloading https://files.pythonhosted.org/packages/7e/90/6141bf41f5655c78e24f40f710fdd4f8a8aff6c8b7c6f0328240f649bdbe/torchvision-0.5.0-cp36-cp36m-manylinux1_x86_64.whl (4.0MB)\n",
58 | "\u001b[K |████████████████████████████████| 4.0MB 34.7MB/s \n",
59 | "\u001b[?25hRequirement already satisfied: tensorboard in /usr/local/lib/python3.6/dist-packages (from crypten) (2.3.0)\n",
60 | "Requirement already satisfied: typing-extensions>=3.6.2.1 in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (3.7.4.2)\n",
61 | "Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (1.15.0)\n",
62 | "Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (1.18.5)\n",
63 | "Requirement already satisfied: protobuf in /usr/local/lib/python3.6/dist-packages (from onnx->crypten) (3.12.4)\n",
64 | "Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision==0.5.0->crypten) (7.0.0)\n",
65 | "Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.9.0)\n",
66 | "Requirement already satisfied: grpcio>=1.24.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.30.0)\n",
67 | "Requirement already satisfied: wheel>=0.26; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.34.2)\n",
68 | "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.0.1)\n",
69 | "Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (2.23.0)\n",
70 | "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (3.2.2)\n",
71 | "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.7.0)\n",
72 | "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (0.4.1)\n",
73 | "Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (49.2.0)\n",
74 | "Requirement already satisfied: google-auth<2,>=1.6.3 in /usr/local/lib/python3.6/dist-packages (from tensorboard->crypten) (1.17.2)\n",
75 | "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (1.24.3)\n",
76 | "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (3.0.4)\n",
77 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (2020.6.20)\n",
78 | "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests<3,>=2.21.0->tensorboard->crypten) (2.10)\n",
79 | "Requirement already satisfied: importlib-metadata; python_version < \"3.8\" in /usr/local/lib/python3.6/dist-packages (from markdown>=2.6.8->tensorboard->crypten) (1.7.0)\n",
80 | "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard->crypten) (1.3.0)\n",
81 | "Requirement already satisfied: rsa<5,>=3.1.4; python_version >= \"3\" in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (4.6)\n",
82 | "Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (4.1.1)\n",
83 | "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.6/dist-packages (from google-auth<2,>=1.6.3->tensorboard->crypten) (0.2.8)\n",
84 | "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/dist-packages (from importlib-metadata; python_version < \"3.8\"->markdown>=2.6.8->tensorboard->crypten) (3.1.0)\n",
85 | "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.6/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard->crypten) (3.1.0)\n",
86 | "Requirement already satisfied: pyasn1>=0.1.3 in /usr/local/lib/python3.6/dist-packages (from rsa<5,>=3.1.4; python_version >= \"3\"->google-auth<2,>=1.6.3->tensorboard->crypten) (0.4.8)\n",
87 | "Installing collected packages: torch, onnx, torchvision, crypten\n",
88 | " Found existing installation: torch 1.6.0+cu101\n",
89 | " Uninstalling torch-1.6.0+cu101:\n",
90 | " Successfully uninstalled torch-1.6.0+cu101\n",
91 | " Found existing installation: torchvision 0.7.0+cu101\n",
92 | " Uninstalling torchvision-0.7.0+cu101:\n",
93 | " Successfully uninstalled torchvision-0.7.0+cu101\n",
94 | "Successfully installed crypten-0.1 onnx-1.7.0 torch-1.4.0 torchvision-0.5.0\n"
95 | ],
96 | "name": "stdout"
97 | }
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "metadata": {
103 | "id": "3V8giUdvdZDZ",
104 | "colab_type": "code",
105 | "colab": {}
106 | },
107 | "source": [
108 | "import torch\n",
109 | "import crypten"
110 | ],
111 | "execution_count": 2,
112 | "outputs": []
113 | },
114 | {
115 | "cell_type": "code",
116 | "metadata": {
117 | "id": "owu_OLffdZGv",
118 | "colab_type": "code",
119 | "colab": {}
120 | },
121 | "source": [
122 | "crypten.init()\n"
123 | ],
124 | "execution_count": 3,
125 | "outputs": []
126 | },
127 | {
128 | "cell_type": "markdown",
129 | "metadata": {
130 | "id": "rbpPrQpXtzhi",
131 | "colab_type": "text"
132 | },
133 | "source": [
134 | "Arithmetic secret-sharing\n",
135 | "Arithmetic secret sharing allows efficient recovery of the secret in the presence of faulty shares, by a generalization of a result and also gives rise to verifiable secret sharing "
136 | ]
137 | },
138 | {
139 | "cell_type": "code",
140 | "metadata": {
141 | "id": "Hb4kA91BdZJd",
142 | "colab_type": "code",
143 | "colab": {
144 | "base_uri": "https://localhost:8080/",
145 | "height": 239
146 | },
147 | "outputId": "3807d5e7-3424-4d37-9a4c-f4db4196e078"
148 | },
149 | "source": [
150 | "import crypten.mpc as mpc\n",
151 | "import crypten.communicator as comm \n",
152 | "\n",
153 | "@mpc.run_multiprocess(world_size=2)\n",
154 | "def examine_arithmetic_shares():\n",
155 | " x_enc = crypten.cryptensor([1, 2, 3], ptype=crypten.arithmetic)\n",
156 | " \n",
157 | " rank = comm.get().get_rank()\n",
158 | " print(f\"Rank {rank}:\\n {x_enc}\")\n",
159 | " \n",
160 | "x = examine_arithmetic_shares()\n",
161 | "\n"
162 | ],
163 | "execution_count": 4,
164 | "outputs": [
165 | {
166 | "output_type": "stream",
167 | "text": [
168 | "Rank 1:\n",
169 | " MPCTensor(\n",
170 | "\t_tensor=tensor([6945554524222524116, 6422998172786036614, 3973450884806121364])\n",
171 | "\tplain_text=HIDDEN\n",
172 | "\tptype=ptype.arithmetic\n",
173 | ")Rank 0:\n",
174 | " MPCTensor(\n",
175 | "\t_tensor=tensor([-6945554524222458580, -6422998172785905542, -3973450884805924756])\n",
176 | "\tplain_text=HIDDEN\n",
177 | "\tptype=ptype.arithmetic\n",
178 | ")\n",
179 | "\n"
180 | ],
181 | "name": "stdout"
182 | }
183 | ]
184 | },
185 | {
186 | "cell_type": "markdown",
187 | "metadata": {
188 | "id": "TEYbP08Zua3s",
189 | "colab_type": "text"
190 | },
191 | "source": [
192 | "Let's look more closely at the crypten.arithmetic ptype. Most of the mathematical operations implemented by CrypTensors are implemented using arithmetic secret sharing. As such, crypten.arithmetic is the default ptype for newly generated CrypTensors.\n",
193 | "\n",
194 | "Let's begin by creating a new CrypTensor using ptype=crypten.arithmetic to enforce that the encryption is done via arithmetic secret sharing. We can print values of each share to confirm that values are being encrypted properly.\n",
195 | "\n",
196 | "To do so, we will need to create multiple parties to hold each share. We do this here using the @mpc.run_multiprocess function decorator, which we developed to execute crypten code from a single script (as we have in a Jupyter notebook). CrypTen follows the standard MPI programming model: it runs a separate process for each party, but each process runs an identical (complete) program. Each process has a rank variable to identify itself.\n",
197 | "\n",
198 | "Note that the sum of the two _tensor attributes below is equal to a scaled representation of the input. (Because MPC requires values to be integers, we scale input floats to a fixed-point encoding before encryption.)"
199 | ]
200 | },
201 | {
202 | "cell_type": "code",
203 | "metadata": {
204 | "id": "xMP6cnIOdZWz",
205 | "colab_type": "code",
206 | "colab": {}
207 | },
208 | "source": [
209 | ""
210 | ],
211 | "execution_count": null,
212 | "outputs": []
213 | },
214 | {
215 | "cell_type": "code",
216 | "metadata": {
217 | "id": "9yS3ndZHdZZc",
218 | "colab_type": "code",
219 | "colab": {}
220 | },
221 | "source": [
222 | ""
223 | ],
224 | "execution_count": null,
225 | "outputs": []
226 | },
227 | {
228 | "cell_type": "code",
229 | "metadata": {
230 | "id": "Rde1dZ2RdZcS",
231 | "colab_type": "code",
232 | "colab": {}
233 | },
234 | "source": [
235 | ""
236 | ],
237 | "execution_count": null,
238 | "outputs": []
239 | }
240 | ]
241 | }
--------------------------------------------------------------------------------