Skip to content

Commit

Permalink
Created using Colaboratory
Browse files Browse the repository at this point in the history
  • Loading branch information
JoyeBright committed Jul 1, 2020
1 parent 6c4d7fa commit 53fa2e9
Showing 1 changed file with 90 additions and 80 deletions.
170 changes: 90 additions & 80 deletions SecretText_Module.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
"name": "SecretText_Module.ipynb",
"provenance": [],
"collapsed_sections": [
"2oW3mZAtj5p2",
"VVoFSwFgkBJB",
"lWrgZTMdklMV",
"qxVHisXPogE_",
"BAAoAr8LucIk",
"lbcguiQfdNLg",
"xaSJr-QdpfWC",
"u-0jN6kVrauQ",
"ULRQ4w5FaxDm",
"PkuOQsLby3Gn",
"k4aDGvsTxaCh",
"PkuOQsLby3Gn",
"KwNEqaNBy3bY"
],
"authorship_tag": "ABX9TyNMoSREo/ik9gNaa4i+WOrq",
"authorship_tag": "ABX9TyPXJ59W0MLCzFHrm3oy+Kbg",
"include_colab_link": true
},
"kernelspec": {
Expand Down Expand Up @@ -57,18 +52,18 @@
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "82b553de-dd4a-44f0-de1e-880ddbfc162f"
"outputId": "7bdaeda9-637e-4fec-c2e5-9916c4befe87"
},
"source": [
"text=\"this is a secret bit stream. My name is Javad PourMostafa and I am going to hide this message!\"\n",
"text=\"this is a secret bit stream.\"\n",
"print(\"number of chars in secret bit:\", len(text))"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"number of chars in secret bit: 94\n"
"number of chars in secret bit: 28\n"
],
"name": "stdout"
}
Expand Down Expand Up @@ -121,9 +116,9 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 88
},
"outputId": "17ff9e48-c37d-4094-f6a9-182ba4f023c4"
"outputId": "a2b268fe-24b5-4d63-dfc4-9ced16de5ef5"
},
"source": [
"print(\"The binary bitsream:\", binary)\n",
Expand All @@ -135,9 +130,9 @@
{
"output_type": "stream",
"text": [
"The binary bitsream: 01110100011010000110100101110011001000000110100101110011001000000110000100100000011100110110010101100011011100100110010101110100001000000110001001101001011101000010000001110011011101000111001001100101011000010110110100101110001000000100110101111001001000000110111001100001011011010110010100100000011010010111001100100000010010100110000101110110011000010110010000100000010100000110111101110101011100100100110101101111011100110111010001100001011001100110000100100000011000010110111001100100001000000100100100100000011000010110110100100000011001110110111101101001011011100110011100100000011101000110111100100000011010000110100101100100011001010010000001110100011010000110100101110011001000000110110101100101011100110111001101100001011001110110010100100001\n",
"Bistream length: 752\n",
"Bistream characters: 94\n"
"The binary bitsream: 01110100011010000110100101110011001000000110100101110011001000000110000100100000011100110110010101100011011100100110010101110100001000000110001001101001011101000010000001110011011101000111001001100101011000010110110100101110\n",
"Bistream length: 224\n",
"Bistream characters: 28\n"
],
"name": "stdout"
}
Expand Down Expand Up @@ -177,19 +172,21 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 51
},
"outputId": "17d39ec3-ff1b-4199-8f74-171f50de8cc8"
"outputId": "70348824-7233-4c49-e2c9-49bf6aed3bc3"
},
"source": [
"print(\"Decimal value of bistream:\", binToDec())"
"print(\"Decimal value of bistream:\", binToDec())\n",
"print(len(str(binToDec())))"
],
"execution_count": 6,
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"text": [
"Decimal value of bistream: 10772067739827798668520995910879052176492261350835919590547186619206944541614464884156097078298606576108374887088393858024886531938915985560205552361299360568696625792366901080879914658886341466675521130316523409569605801698593\n"
"Decimal value of bistream: 12259178403199069570342758845700850558725039128334999982059829685550\n",
"68\n"
],
"name": "stdout"
}
Expand Down Expand Up @@ -228,9 +225,9 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 71
},
"outputId": "3ee65e07-2f95-4e07-ed19-4ec60084a591"
"outputId": "869553fa-9ef4-41c5-c54b-417f43d2cf0e"
},
"source": [
"print(\"Binary bitstream:\", decToBin())\n",
Expand All @@ -241,8 +238,8 @@
{
"output_type": "stream",
"text": [
"Binary bitstream: 1110100011010000110100101110011001000000110100101110011001000000110000100100000011100110110010101100011011100100110010101110100001000000110001001101001011101000010000001110011011101000111001001100101011000010110110100101110001000000100110101111001001000000110111001100001011011010110010100100000011010010111001100100000010010100110000101110110011000010110010000100000010100000110111101110101011100100100110101101111011100110111010001100001011001100110000100100000011000010110111001100100001000000100100100100000011000010110110100100000011001110110111101101001011011100110011100100000011101000110111100100000011010000110100101100100011001010010000001110100011010000110100101110011001000000110110101100101011100110111001101100001011001110110010100100001\n",
"Bistream length: 751\n"
"Binary bitstream: 1110100011010000110100101110011001000000110100101110011001000000110000100100000011100110110010101100011011100100110010101110100001000000110001001101001011101000010000001110011011101000111001001100101011000010110110100101110\n",
"Bistream length: 223\n"
],
"name": "stdout"
}
Expand Down Expand Up @@ -284,9 +281,9 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 34
},
"outputId": "1c6a0b46-8655-4f2d-f3b1-57eeb7d281bf"
"outputId": "8d41a42f-0f41-41c2-e353-a09f3ffac42b"
},
"source": [
"print(text_from_bits(decToBin()))"
Expand All @@ -296,7 +293,7 @@
{
"output_type": "stream",
"text": [
"this is a secret bit stream. My name is Javad PourMostafa and I am going to hide this message!\n"
"this is a secret bit stream.\n"
],
"name": "stdout"
}
Expand All @@ -321,28 +318,30 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 68
},
"outputId": "fe6eda06-d358-4289-a179-e53dff7018d0"
"outputId": "2600c8b4-1c6f-4b08-ccf8-84cd91b7e2ce"
},
"source": [
"print(binToDec())\n",
"digits = [int(d) for d in str(binToDec())]\n",
"#print(digits)\n",
"#print(len(digits))\n",
"num = []\n",
"for n in range(0, len(digits), 4):\n",
" num.append(int(str(digits[n])+''+str(digits[n+1])+''+str(digits[n+2])))\n",
" num.append(int(str(digits[n])+''+str(digits[n+1])+''+str(digits[n+2])+''+str(digits[n+3])))\n",
"signal = num\n",
"print(signal)\n",
"print(len(signal))"
],
"execution_count": 11,
"execution_count": 19,
"outputs": [
{
"output_type": "stream",
"text": [
"[107, 206, 739, 277, 866, 520, 959, 87, 52, 764, 226, 350, 359, 959, 547, 866, 920, 944, 416, 446, 884, 560, 707, 298, 65, 610, 374, 870, 839, 858, 248, 653, 938, 159, 556, 205, 523, 129, 360, 686, 662, 792, 669, 108, 879, 146, 888, 341, 666, 552, 130, 165, 340, 569, 58, 169, 593]\n",
"57\n"
"12259178403199069570342758845700850558725039128334999982059829685550\n",
"[1225, 9178, 4031, 9906, 9570, 3427, 5884, 5700, 8505, 5872, 5039, 1283, 3499, 9982, 598, 2968, 5550]\n",
"17\n"
],
"name": "stdout"
}
Expand Down Expand Up @@ -375,16 +374,16 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 170
},
"outputId": "b1d95929-fcab-47b0-9fc3-d5f027f4b2ae"
"outputId": "aee4dcaa-68d2-40c9-99b8-f271e799428d"
},
"source": [
"import pywt\n",
"print(pywt.Wavelet('haar'))\n",
"cA, cD = pywt.dwt(signal, 'haar', mode='zero')"
],
"execution_count": 12,
"execution_count": 40,
"outputs": [
{
"output_type": "stream",
Expand All @@ -410,31 +409,25 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 119
},
"outputId": "6aa83b12-ab4d-4e8f-f14d-69eb03028946"
"outputId": "b35f7054-c5a4-45e7-c187-8aaf734a5cfe"
},
"source": [
"print(cA)\n",
"print(cD)"
],
"execution_count": 13,
"execution_count": 41,
"outputs": [
{
"output_type": "stream",
"text": [
"[ 221.32442251 718.42048969 980.04999872 739.63369312 576.99913345\n",
" 407.29350596 931.9667376 999.14188182 1318.04704013 609.52604538\n",
" 1021.06219203 710.64231509 477.2970773 879.6408358 1199.96020767\n",
" 637.10320985 775.69613896 538.10826048 461.03362133 739.63369312\n",
" 1028.13325985 549.42196898 724.78445072 869.03423408 861.25605949\n",
" 208.59650045 642.7600641 160.51323933 419.31432124]\n",
"[ -70.00357134 326.68333291 244.65894629 616.59711319 -503.4600282\n",
" -87.68124087 -424.26406871 -225.5670632 -16.97056275 -21.21320344\n",
" 229.1025971 289.20667351 -385.37319575 -350.72496347 -13.43502884\n",
" -286.37824638 550.83618254 248.1944802 278.60007179 -230.51681067\n",
" -91.92388155 396.68690425 518.30927061 386.78740931 80.61017306\n",
" -24.74873734 -161.92745289 -78.48885271 419.31432124]\n"
"[ 7356.03184468 9854.9472094 9190.26683508 8191.12495326\n",
" 10166.07419312 4470.32907066 9532.50651718 2521.54278171\n",
" 3924.44263559]\n",
"[-5623.62023078 -4154.25233947 4343.75695683 130.10764774\n",
" 1861.81215486 2655.89307014 -4584.17326243 -1675.84307141\n",
" 3924.44263559]\n"
],
"name": "stdout"
}
Expand All @@ -457,27 +450,24 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 0
"height": 68
},
"outputId": "894b0af1-be43-41a6-a708-e85d5ddf8d3a"
"outputId": "58035494-aa34-4b39-ee66-4a9e4ee4ea71"
},
"source": [
"coe = pywt.idwt(cA, cD, 'haar')\n",
"coe = coe.astype(int)\n",
"print(pywt.idwt(cA, cD, 'haar'))\n",
"print(len(pywt.idwt(cA, cD, 'haar')))"
],
"execution_count": 14,
"execution_count": 36,
"outputs": [
{
"output_type": "stream",
"text": [
"[107. 206. 739. 277. 866. 520. 959. 87. 52. 764. 226. 350. 359. 959.\n",
" 547. 866. 920. 944. 416. 446. 884. 560. 707. 298. 65. 610. 374. 870.\n",
" 839. 858. 248. 653. 938. 159. 556. 205. 523. 129. 360. 686. 662. 792.\n",
" 669. 108. 879. 146. 888. 341. 666. 552. 130. 165. 340. 569. 58. 169.\n",
" 593. 0.]\n",
"58\n"
"[1225. 9178. 4031. 9906. 9570. 3427. 5884. 5700. 8505. 5872. 5039. 1283.\n",
" 3499. 9982. 598. 2968. 5550. 0.]\n",
"18\n"
],
"name": "stdout"
}
Expand Down Expand Up @@ -508,12 +498,12 @@
" index = []\n",
" for n in range(0, size, 2):\n",
" if(n==size-1): signal.append(signal[n]) # padding to make a pair (rewrite the last number)\n",
" s.append(int((signal[n]+signal[n+1])/(2))) \n",
" s.append(int((signal[n]+signal[n+1])/(2)))\n",
" if((signal[n]+signal[n+1])%2 !=0): index.append(n)\n",
" d.append(int((signal[n]-signal[n+1])/(2)))\n",
" return s, d, index"
],
"execution_count": 15,
"execution_count": 20,
"outputs": []
},
{
Expand All @@ -523,23 +513,23 @@
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 71
"height": 51
},
"outputId": "ea93e277-ff01-45cd-f468-cde50202f9fe"
"outputId": "bcacc737-5428-48a9-c13f-062c799f080a"
},
"source": [
"data=[9, 7, 3, 5, 21, 2, 2]\n",
"cS, cD, Index = haarWavelet(signal)\n",
"print(cS, cD)\n",
"print(Index)"
],
"execution_count": 16,
"execution_count": 21,
"outputs": [
{
"output_type": "stream",
"text": [
"[156, 508, 693, 523, 408, 288, 659, 706, 932, 431, 722, 502, 337, 622, 848, 450, 548, 380, 326, 523, 727, 388, 512, 614, 609, 147, 454, 113, 593] [-49, 231, 173, 436, -356, -62, -300, -159, -12, -15, 162, 204, -272, -248, -9, -202, 389, 175, 197, -163, -65, 280, 366, 273, 57, -17, -114, -55, 0]\n",
"[0, 14, 22, 24, 28, 30, 32, 34, 42, 44, 46, 50, 52, 54]\n"
"[519, 696, 649, 579, 718, 315, 673, 177, 555] [-397, -293, 307, 9, 131, 187, -324, -118, 0]\n",
"[0, 2, 4, 8, 10, 12, 14]\n"
],
"name": "stdout"
}
Expand All @@ -564,23 +554,28 @@
"base_uri": "https://localhost:8080/",
"height": 102
},
"outputId": "ae7ca43c-1da6-402a-ccf7-0512d0043bf2"
"outputId": "5f1a50ec-eea4-4eb7-d4b7-45f114d5c73e"
},
"source": [
"import numpy as np\n",
"coefficient = np.concatenate((cS, cD), axis=None)\n",
"print(coefficient)"
"print(coefficient)\n",
"coefficient = coefficient.astype(str).tolist()\n",
"print(coefficient)\n",
"coefficient = ''.join(coefficient)\n",
"print(coefficient)\n",
"print(type(coefficient))\n"
],
"execution_count": 17,
"execution_count": 44,
"outputs": [
{
"output_type": "stream",
"text": [
"[ 156 508 693 523 408 288 659 706 932 431 722 502 337 622\n",
" 848 450 548 380 326 523 727 388 512 614 609 147 454 113\n",
" 593 -49 231 173 436 -356 -62 -300 -159 -12 -15 162 204 -272\n",
" -248 -9 -202 389 175 197 -163 -65 280 366 273 57 -17 -114\n",
" -55 0]\n"
"[ 519 696 649 579 718 315 673 177 555 -397 -293 307 9 131\n",
" 187 -324 -118 0]\n",
"['519', '696', '649', '579', '718', '315', '673', '177', '555', '-397', '-293', '307', '9', '131', '187', '-324', '-118', '0']\n",
"519696649579718315673177555-397-2933079131187-324-1180\n",
"<class 'str'>\n"
],
"name": "stdout"
}
Expand All @@ -591,20 +586,35 @@
"metadata": {
"id": "65HFBbMUy6We",
"colab_type": "code",
"colab": {}
"colab": {
"base_uri": "https://localhost:8080/",
"height": 317
},
"outputId": "074cbda2-f0db-4f61-c060-8f0de2a84638"
},
"source": [
"bin = []\n",
"import sys\n",
"sys.setrecursionlimit(1500)\n",
"for n in range(0, len(coefficient)):\n",
" bin.append(decToBin(coefficient[n]))\n",
"new_binary = \"\".join(bin)\n",
"print(new_binary)\n",
"print(len(new_binary))"
],
"execution_count": null,
"outputs": []
"execution_count": 40,
"outputs": [
{
"output_type": "error",
"ename": "TypeError",
"evalue": "ignored",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-40-6e1e4e01afbe>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mbin\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcoefficient\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mbin\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdecToBin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcoefficient\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mnew_binary\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbin\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_binary\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-15-b91371cb9b84>\u001b[0m in \u001b[0;36mdecToBin\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m''\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mdecToBin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m%\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for //: 'str' and 'int'"
]
}
]
},
{
"cell_type": "markdown",
Expand Down

0 comments on commit 53fa2e9

Please sign in to comment.