From 48d3baf9803f673a101f6360a3d40b8211ec3e10 Mon Sep 17 00:00:00 2001
From: Navan Chauhan The program first compares if the first number is not 0. If the number is not 0, then the <script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
<script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
-<style>
- .arjs-loader {
- height: 100%;
- width: 100%;
- position: absolute;
- top: 0;
- left: 0;
- background-color: rgba(0, 0, 0, 0.8);
- z-index: 9999;
- display: flex;
- justify-content: center;
- align-items: center;
- }
-
- .arjs-loader div {
- text-align: center;
- font-size: 1.25em;
- color: white;
- }
+<style>
+ .arjs-loader {
+ height: 100%;
+ width: 100%;
+ position: absolute;
+ top: 0;
+ left: 0;
+ background-color: rgba(0, 0, 0, 0.8);
+ z-index: 9999;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .arjs-loader div {
+ text-align: center;
+ font-size: 1.25em;
+ color: white;
+ }
</style>
<body style="margin : 0px; overflow: hidden;">
@@ -1677,31 +1677,31 @@ values using the X values. We then plot it to compare the actual data and predic
Epoch 1000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 2000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 3000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 4000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 5000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 6000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 7000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 8000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 9000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 10000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 11000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 12000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 13000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 14000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 15000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 16000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 17000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 18000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 19000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 20000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 21000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 22000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 23000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 24000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
-Epoch 25000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+
Epoch 1000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 2000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 3000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 4000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 5000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 6000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 7000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 8000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 9000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 10000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 11000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 12000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 13000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 14000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 15000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 16000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 17000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 18000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 19000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 20000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 21000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 22000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 23000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 24000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
+Epoch 25000 : Training Cost: 88999125000.0 a,b: 180396.42 -478869.12
88999125000.0 180396.42 -478869.12
Epoch 1000 : Training Cost: 52571360000.0 a,b,c: 1002.4456 1097.0197 1276.6921
-Epoch 2000 : Training Cost: 37798890000.0 a,b,c: 1952.4263 2130.2825 2469.7756
-Epoch 3000 : Training Cost: 26751185000.0 a,b,c: 2839.5825 3081.6118 3554.351
-Epoch 4000 : Training Cost: 19020106000.0 a,b,c: 3644.56 3922.9563 4486.3135
-Epoch 5000 : Training Cost: 14060446000.0 a,b,c: 4345.042 4621.4233 5212.693
-Epoch 6000 : Training Cost: 11201084000.0 a,b,c: 4921.1855 5148.1504 5689.0713
-Epoch 7000 : Training Cost: 9732740000.0 a,b,c: 5364.764 5493.0156 5906.754
-Epoch 8000 : Training Cost: 9050918000.0 a,b,c: 5685.4067 5673.182 5902.0728
-Epoch 9000 : Training Cost: 8750394000.0 a,b,c: 5906.9814 5724.8906 5734.746
-Epoch 10000 : Training Cost: 8613128000.0 a,b,c: 6057.3677 5687.3364 5461.167
-Epoch 11000 : Training Cost: 8540034600.0 a,b,c: 6160.547 5592.3022 5122.8633
-Epoch 12000 : Training Cost: 8490983000.0 a,b,c: 6233.9175 5462.025 4747.111
-Epoch 13000 : Training Cost: 8450816500.0 a,b,c: 6289.048 5310.7583 4350.6997
-Epoch 14000 : Training Cost: 8414082000.0 a,b,c: 6333.199 5147.394 3943.9294
-Epoch 15000 : Training Cost: 8378841600.0 a,b,c: 6370.7944 4977.1704 3532.476
-Epoch 16000 : Training Cost: 8344471000.0 a,b,c: 6404.468 4803.542 3120.2087
-Epoch 17000 : Training Cost: 8310785500.0 a,b,c: 6435.365 4628.1523 2709.1445
-Epoch 18000 : Training Cost: 8277482000.0 a,b,c: 6465.5493 4451.833 2300.2783
-Epoch 19000 : Training Cost: 8244650000.0 a,b,c: 6494.609 4274.826 1894.3738
-Epoch 20000 : Training Cost: 8212349000.0 a,b,c: 6522.8247 4098.1733 1491.9915
-Epoch 21000 : Training Cost: 8180598300.0 a,b,c: 6550.6567 3922.7405 1093.3868
-Epoch 22000 : Training Cost: 8149257700.0 a,b,c: 6578.489 3747.8362 698.53357
-Epoch 23000 : Training Cost: 8118325000.0 a,b,c: 6606.1973 3573.2742 307.3541
-Epoch 24000 : Training Cost: 8088001000.0 a,b,c: 6632.96 3399.878 -79.89219
-Epoch 25000 : Training Cost: 8058094600.0 a,b,c: 6659.793 3227.2517 -463.03156
+
Epoch 1000 : Training Cost: 52571360000.0 a,b,c: 1002.4456 1097.0197 1276.6921
+Epoch 2000 : Training Cost: 37798890000.0 a,b,c: 1952.4263 2130.2825 2469.7756
+Epoch 3000 : Training Cost: 26751185000.0 a,b,c: 2839.5825 3081.6118 3554.351
+Epoch 4000 : Training Cost: 19020106000.0 a,b,c: 3644.56 3922.9563 4486.3135
+Epoch 5000 : Training Cost: 14060446000.0 a,b,c: 4345.042 4621.4233 5212.693
+Epoch 6000 : Training Cost: 11201084000.0 a,b,c: 4921.1855 5148.1504 5689.0713
+Epoch 7000 : Training Cost: 9732740000.0 a,b,c: 5364.764 5493.0156 5906.754
+Epoch 8000 : Training Cost: 9050918000.0 a,b,c: 5685.4067 5673.182 5902.0728
+Epoch 9000 : Training Cost: 8750394000.0 a,b,c: 5906.9814 5724.8906 5734.746
+Epoch 10000 : Training Cost: 8613128000.0 a,b,c: 6057.3677 5687.3364 5461.167
+Epoch 11000 : Training Cost: 8540034600.0 a,b,c: 6160.547 5592.3022 5122.8633
+Epoch 12000 : Training Cost: 8490983000.0 a,b,c: 6233.9175 5462.025 4747.111
+Epoch 13000 : Training Cost: 8450816500.0 a,b,c: 6289.048 5310.7583 4350.6997
+Epoch 14000 : Training Cost: 8414082000.0 a,b,c: 6333.199 5147.394 3943.9294
+Epoch 15000 : Training Cost: 8378841600.0 a,b,c: 6370.7944 4977.1704 3532.476
+Epoch 16000 : Training Cost: 8344471000.0 a,b,c: 6404.468 4803.542 3120.2087
+Epoch 17000 : Training Cost: 8310785500.0 a,b,c: 6435.365 4628.1523 2709.1445
+Epoch 18000 : Training Cost: 8277482000.0 a,b,c: 6465.5493 4451.833 2300.2783
+Epoch 19000 : Training Cost: 8244650000.0 a,b,c: 6494.609 4274.826 1894.3738
+Epoch 20000 : Training Cost: 8212349000.0 a,b,c: 6522.8247 4098.1733 1491.9915
+Epoch 21000 : Training Cost: 8180598300.0 a,b,c: 6550.6567 3922.7405 1093.3868
+Epoch 22000 : Training Cost: 8149257700.0 a,b,c: 6578.489 3747.8362 698.53357
+Epoch 23000 : Training Cost: 8118325000.0 a,b,c: 6606.1973 3573.2742 307.3541
+Epoch 24000 : Training Cost: 8088001000.0 a,b,c: 6632.96 3399.878 -79.89219
+Epoch 25000 : Training Cost: 8058094600.0 a,b,c: 6659.793 3227.2517 -463.03156
8058094600.0 6659.793 3227.2517 -463.03156
Epoch 1000 : Training Cost: 4279814000.0 a,b,c,d: 670.1527 694.4212 751.4653 903.9527
-Epoch 2000 : Training Cost: 3770950400.0 a,b,c,d: 742.6414 666.3489 636.94525 859.2088
-Epoch 3000 : Training Cost: 3717708300.0 a,b,c,d: 756.2582 569.3339 448.105 748.23956
-Epoch 4000 : Training Cost: 3667464000.0 a,b,c,d: 769.4476 474.0318 265.5761 654.75525
-Epoch 5000 : Training Cost: 3620040700.0 a,b,c,d: 782.32324 380.54272 89.39888 578.5136
-Epoch 6000 : Training Cost: 3575265800.0 a,b,c,d: 794.8898 288.83356 -80.5215 519.13654
-Epoch 7000 : Training Cost: 3532972000.0 a,b,c,d: 807.1608 198.87044 -244.31102 476.2061
-Epoch 8000 : Training Cost: 3493009200.0 a,b,c,d: 819.13513 110.64169 -402.0677 449.3291
-Epoch 9000 : Training Cost: 3455228400.0 a,b,c,d: 830.80255 24.0964 -553.92804 438.0652
-Epoch 10000 : Training Cost: 3419475500.0 a,b,c,d: 842.21594 -60.797424 -700.0123 441.983
-Epoch 11000 : Training Cost: 3385625300.0 a,b,c,d: 853.3363 -144.08699 -840.467 460.6356
-Epoch 12000 : Training Cost: 3353544700.0 a,b,c,d: 864.19135 -225.8125 -975.4196 493.57703
-Epoch 13000 : Training Cost: 3323125000.0 a,b,c,d: 874.778 -305.98932 -1104.9867 540.39465
-Epoch 14000 : Training Cost: 3294257000.0 a,b,c,d: 885.1007 -384.63474 -1229.277 600.65607
-Epoch 15000 : Training Cost: 3266820000.0 a,b,c,d: 895.18823 -461.819 -1348.4417 673.9051
-Epoch 16000 : Training Cost: 3240736000.0 a,b,c,d: 905.0128 -537.541 -1462.6171 759.7118
-Epoch 17000 : Training Cost: 3215895000.0 a,b,c,d: 914.60065 -611.8676 -1571.9058 857.6638
-Epoch 18000 : Training Cost: 3192216800.0 a,b,c,d: 923.9603 -684.8093 -1676.4642 967.30475
-Epoch 19000 : Training Cost: 3169632300.0 a,b,c,d: 933.08594 -756.3582 -1776.4275 1088.2198
-Epoch 20000 : Training Cost: 3148046300.0 a,b,c,d: 941.9928 -826.6257 -1871.9355 1219.9702
-Epoch 21000 : Training Cost: 3127394800.0 a,b,c,d: 950.67896 -895.6205 -1963.0989 1362.1665
-Epoch 22000 : Training Cost: 3107608600.0 a,b,c,d: 959.1487 -963.38116 -2050.0586 1514.4026
-Epoch 23000 : Training Cost: 3088618200.0 a,b,c,d: 967.4355 -1029.9625 -2132.961 1676.2717
-Epoch 24000 : Training Cost: 3070361300.0 a,b,c,d: 975.52875 -1095.4292 -2211.854 1847.4485
-Epoch 25000 : Training Cost: 3052791300.0 a,b,c,d: 983.4346 -1159.7922 -2286.9412 2027.4857
+
Epoch 1000 : Training Cost: 4279814000.0 a,b,c,d: 670.1527 694.4212 751.4653 903.9527
+Epoch 2000 : Training Cost: 3770950400.0 a,b,c,d: 742.6414 666.3489 636.94525 859.2088
+Epoch 3000 : Training Cost: 3717708300.0 a,b,c,d: 756.2582 569.3339 448.105 748.23956
+Epoch 4000 : Training Cost: 3667464000.0 a,b,c,d: 769.4476 474.0318 265.5761 654.75525
+Epoch 5000 : Training Cost: 3620040700.0 a,b,c,d: 782.32324 380.54272 89.39888 578.5136
+Epoch 6000 : Training Cost: 3575265800.0 a,b,c,d: 794.8898 288.83356 -80.5215 519.13654
+Epoch 7000 : Training Cost: 3532972000.0 a,b,c,d: 807.1608 198.87044 -244.31102 476.2061
+Epoch 8000 : Training Cost: 3493009200.0 a,b,c,d: 819.13513 110.64169 -402.0677 449.3291
+Epoch 9000 : Training Cost: 3455228400.0 a,b,c,d: 830.80255 24.0964 -553.92804 438.0652
+Epoch 10000 : Training Cost: 3419475500.0 a,b,c,d: 842.21594 -60.797424 -700.0123 441.983
+Epoch 11000 : Training Cost: 3385625300.0 a,b,c,d: 853.3363 -144.08699 -840.467 460.6356
+Epoch 12000 : Training Cost: 3353544700.0 a,b,c,d: 864.19135 -225.8125 -975.4196 493.57703
+Epoch 13000 : Training Cost: 3323125000.0 a,b,c,d: 874.778 -305.98932 -1104.9867 540.39465
+Epoch 14000 : Training Cost: 3294257000.0 a,b,c,d: 885.1007 -384.63474 -1229.277 600.65607
+Epoch 15000 : Training Cost: 3266820000.0 a,b,c,d: 895.18823 -461.819 -1348.4417 673.9051
+Epoch 16000 : Training Cost: 3240736000.0 a,b,c,d: 905.0128 -537.541 -1462.6171 759.7118
+Epoch 17000 : Training Cost: 3215895000.0 a,b,c,d: 914.60065 -611.8676 -1571.9058 857.6638
+Epoch 18000 : Training Cost: 3192216800.0 a,b,c,d: 923.9603 -684.8093 -1676.4642 967.30475
+Epoch 19000 : Training Cost: 3169632300.0 a,b,c,d: 933.08594 -756.3582 -1776.4275 1088.2198
+Epoch 20000 : Training Cost: 3148046300.0 a,b,c,d: 941.9928 -826.6257 -1871.9355 1219.9702
+Epoch 21000 : Training Cost: 3127394800.0 a,b,c,d: 950.67896 -895.6205 -1963.0989 1362.1665
+Epoch 22000 : Training Cost: 3107608600.0 a,b,c,d: 959.1487 -963.38116 -2050.0586 1514.4026
+Epoch 23000 : Training Cost: 3088618200.0 a,b,c,d: 967.4355 -1029.9625 -2132.961 1676.2717
+Epoch 24000 : Training Cost: 3070361300.0 a,b,c,d: 975.52875 -1095.4292 -2211.854 1847.4485
+Epoch 25000 : Training Cost: 3052791300.0 a,b,c,d: 983.4346 -1159.7922 -2286.9412 2027.4857
3052791300.0 983.4346 -1159.7922 -2286.9412 2027.4857
Epoch 1000 : Training Cost: 1902632600.0 a,b,c,d: 84.48304 52.210594 54.791424 142.51952 512.0343
-Epoch 2000 : Training Cost: 1854316200.0 a,b,c,d: 88.998955 13.073557 14.276088 223.55667 1056.4655
-Epoch 3000 : Training Cost: 1812812400.0 a,b,c,d: 92.9462 -22.331177 -15.262934 327.41858 1634.9054
-Epoch 4000 : Training Cost: 1775716000.0 a,b,c,d: 96.42522 -54.64535 -35.829437 449.5028 2239.1392
-Epoch 5000 : Training Cost: 1741494100.0 a,b,c,d: 99.524734 -84.43976 -49.181057 585.85876 2862.4915
-Epoch 6000 : Training Cost: 1709199600.0 a,b,c,d: 102.31984 -112.19895 -56.808075 733.1876 3499.6199
-Epoch 7000 : Training Cost: 1678261800.0 a,b,c,d: 104.87324 -138.32709 -59.9442 888.79626 4146.2944
-Epoch 8000 : Training Cost: 1648340600.0 a,b,c,d: 107.23536 -163.15173 -59.58964 1050.524 4798.979
-Epoch 9000 : Training Cost: 1619243400.0 a,b,c,d: 109.44742 -186.9409 -56.53944 1216.6432 5454.9463
-Epoch 10000 : Training Cost: 1590821900.0 a,b,c,d: 111.54233 -209.91287 -51.423084 1385.8513 6113.5137
-Epoch 11000 : Training Cost: 1563042200.0 a,b,c,d: 113.54405 -232.21953 -44.73371 1557.1084 6771.7046
-Epoch 12000 : Training Cost: 1535855600.0 a,b,c,d: 115.471565 -253.9838 -36.851135 1729.535 7429.069
-Epoch 13000 : Training Cost: 1509255300.0 a,b,c,d: 117.33939 -275.29697 -28.0714 1902.5308 8083.9634
-Epoch 14000 : Training Cost: 1483227000.0 a,b,c,d: 119.1605 -296.2472 -18.618649 2075.6094 8735.381
-Epoch 15000 : Training Cost: 1457726700.0 a,b,c,d: 120.94584 -316.915 -8.650095 2248.3247 9384.197
-Epoch 16000 : Training Cost: 1432777300.0 a,b,c,d: 122.69806 -337.30704 1.7027153 2420.5771 10028.871
-Epoch 17000 : Training Cost: 1408365000.0 a,b,c,d: 124.42179 -357.45245 12.33499 2592.2983 10669.157
-Epoch 18000 : Training Cost: 1384480000.0 a,b,c,d: 126.12332 -377.39734 23.168756 2763.0933 11305.027
-Epoch 19000 : Training Cost: 1361116800.0 a,b,c,d: 127.80568 -397.16415 34.160156 2933.0452 11935.669
-Epoch 20000 : Training Cost: 1338288100.0 a,b,c,d: 129.4674 -416.72803 45.259155 3101.7727 12561.179
-Epoch 21000 : Training Cost: 1315959700.0 a,b,c,d: 131.11403 -436.14285 56.4436 3269.3142 13182.058
-Epoch 22000 : Training Cost: 1294164700.0 a,b,c,d: 132.74377 -455.3779 67.6757 3435.3833 13796.807
-Epoch 23000 : Training Cost: 1272863600.0 a,b,c,d: 134.35779 -474.45316 78.96117 3600.264 14406.58
-Epoch 24000 : Training Cost: 1252052600.0 a,b,c,d: 135.9583 -493.38254 90.268616 3764.0078 15010.481
-Epoch 25000 : Training Cost: 1231713700.0 a,b,c,d: 137.54753 -512.1876 101.59372 3926.4897 15609.368
+
Epoch 1000 : Training Cost: 1902632600.0 a,b,c,d: 84.48304 52.210594 54.791424 142.51952 512.0343
+Epoch 2000 : Training Cost: 1854316200.0 a,b,c,d: 88.998955 13.073557 14.276088 223.55667 1056.4655
+Epoch 3000 : Training Cost: 1812812400.0 a,b,c,d: 92.9462 -22.331177 -15.262934 327.41858 1634.9054
+Epoch 4000 : Training Cost: 1775716000.0 a,b,c,d: 96.42522 -54.64535 -35.829437 449.5028 2239.1392
+Epoch 5000 : Training Cost: 1741494100.0 a,b,c,d: 99.524734 -84.43976 -49.181057 585.85876 2862.4915
+Epoch 6000 : Training Cost: 1709199600.0 a,b,c,d: 102.31984 -112.19895 -56.808075 733.1876 3499.6199
+Epoch 7000 : Training Cost: 1678261800.0 a,b,c,d: 104.87324 -138.32709 -59.9442 888.79626 4146.2944
+Epoch 8000 : Training Cost: 1648340600.0 a,b,c,d: 107.23536 -163.15173 -59.58964 1050.524 4798.979
+Epoch 9000 : Training Cost: 1619243400.0 a,b,c,d: 109.44742 -186.9409 -56.53944 1216.6432 5454.9463
+Epoch 10000 : Training Cost: 1590821900.0 a,b,c,d: 111.54233 -209.91287 -51.423084 1385.8513 6113.5137
+Epoch 11000 : Training Cost: 1563042200.0 a,b,c,d: 113.54405 -232.21953 -44.73371 1557.1084 6771.7046
+Epoch 12000 : Training Cost: 1535855600.0 a,b,c,d: 115.471565 -253.9838 -36.851135 1729.535 7429.069
+Epoch 13000 : Training Cost: 1509255300.0 a,b,c,d: 117.33939 -275.29697 -28.0714 1902.5308 8083.9634
+Epoch 14000 : Training Cost: 1483227000.0 a,b,c,d: 119.1605 -296.2472 -18.618649 2075.6094 8735.381
+Epoch 15000 : Training Cost: 1457726700.0 a,b,c,d: 120.94584 -316.915 -8.650095 2248.3247 9384.197
+Epoch 16000 : Training Cost: 1432777300.0 a,b,c,d: 122.69806 -337.30704 1.7027153 2420.5771 10028.871
+Epoch 17000 : Training Cost: 1408365000.0 a,b,c,d: 124.42179 -357.45245 12.33499 2592.2983 10669.157
+Epoch 18000 : Training Cost: 1384480000.0 a,b,c,d: 126.12332 -377.39734 23.168756 2763.0933 11305.027
+Epoch 19000 : Training Cost: 1361116800.0 a,b,c,d: 127.80568 -397.16415 34.160156 2933.0452 11935.669
+Epoch 20000 : Training Cost: 1338288100.0 a,b,c,d: 129.4674 -416.72803 45.259155 3101.7727 12561.179
+Epoch 21000 : Training Cost: 1315959700.0 a,b,c,d: 131.11403 -436.14285 56.4436 3269.3142 13182.058
+Epoch 22000 : Training Cost: 1294164700.0 a,b,c,d: 132.74377 -455.3779 67.6757 3435.3833 13796.807
+Epoch 23000 : Training Cost: 1272863600.0 a,b,c,d: 134.35779 -474.45316 78.96117 3600.264 14406.58
+Epoch 24000 : Training Cost: 1252052600.0 a,b,c,d: 135.9583 -493.38254 90.268616 3764.0078 15010.481
+Epoch 25000 : Training Cost: 1231713700.0 a,b,c,d: 137.54753 -512.1876 101.59372 3926.4897 15609.368
1231713700.0 137.54753 -512.1876 101.59372 3926.4897 15609.368
Epoch 1000 : Training Cost: 1409200100.0 a,b,c,d,e,f: 7.949472 7.46219 55.626034 184.29028 484.00223 1024.0083
-Epoch 2000 : Training Cost: 1306882400.0 a,b,c,d,e,f: 8.732181 -4.0085897 73.25298 315.90103 904.08887 2004.9749
-Epoch 3000 : Training Cost: 1212606000.0 a,b,c,d,e,f: 9.732249 -16.90125 86.28379 437.06552 1305.055 2966.2188
-Epoch 4000 : Training Cost: 1123640400.0 a,b,c,d,e,f: 10.74851 -29.82692 98.59997 555.331 1698.4631 3917.9155
-Epoch 5000 : Training Cost: 1039694300.0 a,b,c,d,e,f: 11.75426 -42.598194 110.698326 671.64355 2085.5513 4860.8535
-Epoch 6000 : Training Cost: 960663550.0 a,b,c,d,e,f: 12.745439 -55.18337 122.644936 786.00214 2466.1638 5794.3735
-Epoch 7000 : Training Cost: 886438340.0 a,b,c,d,e,f: 13.721028 -67.57168 134.43822 898.3691 2839.9958 6717.659
-Epoch 8000 : Training Cost: 816913100.0 a,b,c,d,e,f: 14.679965 -79.75113 146.07385 1008.66895 3206.6692 7629.812
-Epoch 9000 : Training Cost: 751971500.0 a,b,c,d,e,f: 15.62181 -91.71608 157.55713 1116.7715 3565.8323 8529.976
-Epoch 10000 : Training Cost: 691508740.0 a,b,c,d,e,f: 16.545347 -103.4531 168.88321 1222.6348 3916.9785 9416.236
-Epoch 11000 : Training Cost: 635382000.0 a,b,c,d,e,f: 17.450052 -114.954254 180.03932 1326.1565 4259.842 10287.99
-Epoch 12000 : Training Cost: 583477250.0 a,b,c,d,e,f: 18.334944 -126.20821 191.02948 1427.2095 4593.8 11143.449
-Epoch 13000 : Training Cost: 535640400.0 a,b,c,d,e,f: 19.198917 -137.20206 201.84718 1525.6926 4918.5327 11981.633
-Epoch 14000 : Training Cost: 491722240.0 a,b,c,d,e,f: 20.041153 -147.92719 212.49709 1621.5496 5233.627 12800.468
-Epoch 15000 : Training Cost: 451559520.0 a,b,c,d,e,f: 20.860966 -158.37456 222.97133 1714.7141 5538.676 13598.337
-Epoch 16000 : Training Cost: 414988960.0 a,b,c,d,e,f: 21.657421 -168.53406 233.27422 1805.0874 5833.1978 14373.658
-Epoch 17000 : Training Cost: 381837920.0 a,b,c,d,e,f: 22.429693 -178.39536 243.39914 1892.5883 6116.847 15124.394
-Epoch 18000 : Training Cost: 351931300.0 a,b,c,d,e,f: 23.176882 -187.94789 253.3445 1977.137 6389.117 15848.417
-Epoch 19000 : Training Cost: 325074400.0 a,b,c,d,e,f: 23.898485 -197.18741 263.12512 2058.6716 6649.8037 16543.95
-Epoch 20000 : Training Cost: 301073570.0 a,b,c,d,e,f: 24.593851 -206.10497 272.72385 2137.1797 6898.544 17209.367
-Epoch 21000 : Training Cost: 279727000.0 a,b,c,d,e,f: 25.262104 -214.69217 282.14642 2212.6372 7135.217 17842.854
-Epoch 22000 : Training Cost: 260845550.0 a,b,c,d,e,f: 25.903376 -222.94969 291.4003 2284.9844 7359.4644 18442.408
-Epoch 23000 : Training Cost: 244218030.0 a,b,c,d,e,f: 26.517094 -230.8697 300.45532 2354.3003 7571.261 19007.49
-Epoch 24000 : Training Cost: 229660080.0 a,b,c,d,e,f: 27.102589 -238.44817 309.35342 2420.4185 7770.5728 19536.19
-Epoch 25000 : Training Cost: 216972400.0 a,b,c,d,e,f: 27.660324 -245.69016 318.10062 2483.3608 7957.354 20027.707
+
Epoch 1000 : Training Cost: 1409200100.0 a,b,c,d,e,f: 7.949472 7.46219 55.626034 184.29028 484.00223 1024.0083
+Epoch 2000 : Training Cost: 1306882400.0 a,b,c,d,e,f: 8.732181 -4.0085897 73.25298 315.90103 904.08887 2004.9749
+Epoch 3000 : Training Cost: 1212606000.0 a,b,c,d,e,f: 9.732249 -16.90125 86.28379 437.06552 1305.055 2966.2188
+Epoch 4000 : Training Cost: 1123640400.0 a,b,c,d,e,f: 10.74851 -29.82692 98.59997 555.331 1698.4631 3917.9155
+Epoch 5000 : Training Cost: 1039694300.0 a,b,c,d,e,f: 11.75426 -42.598194 110.698326 671.64355 2085.5513 4860.8535
+Epoch 6000 : Training Cost: 960663550.0 a,b,c,d,e,f: 12.745439 -55.18337 122.644936 786.00214 2466.1638 5794.3735
+Epoch 7000 : Training Cost: 886438340.0 a,b,c,d,e,f: 13.721028 -67.57168 134.43822 898.3691 2839.9958 6717.659
+Epoch 8000 : Training Cost: 816913100.0 a,b,c,d,e,f: 14.679965 -79.75113 146.07385 1008.66895 3206.6692 7629.812
+Epoch 9000 : Training Cost: 751971500.0 a,b,c,d,e,f: 15.62181 -91.71608 157.55713 1116.7715 3565.8323 8529.976
+Epoch 10000 : Training Cost: 691508740.0 a,b,c,d,e,f: 16.545347 -103.4531 168.88321 1222.6348 3916.9785 9416.236
+Epoch 11000 : Training Cost: 635382000.0 a,b,c,d,e,f: 17.450052 -114.954254 180.03932 1326.1565 4259.842 10287.99
+Epoch 12000 : Training Cost: 583477250.0 a,b,c,d,e,f: 18.334944 -126.20821 191.02948 1427.2095 4593.8 11143.449
+Epoch 13000 : Training Cost: 535640400.0 a,b,c,d,e,f: 19.198917 -137.20206 201.84718 1525.6926 4918.5327 11981.633
+Epoch 14000 : Training Cost: 491722240.0 a,b,c,d,e,f: 20.041153 -147.92719 212.49709 1621.5496 5233.627 12800.468
+Epoch 15000 : Training Cost: 451559520.0 a,b,c,d,e,f: 20.860966 -158.37456 222.97133 1714.7141 5538.676 13598.337
+Epoch 16000 : Training Cost: 414988960.0 a,b,c,d,e,f: 21.657421 -168.53406 233.27422 1805.0874 5833.1978 14373.658
+Epoch 17000 : Training Cost: 381837920.0 a,b,c,d,e,f: 22.429693 -178.39536 243.39914 1892.5883 6116.847 15124.394
+Epoch 18000 : Training Cost: 351931300.0 a,b,c,d,e,f: 23.176882 -187.94789 253.3445 1977.137 6389.117 15848.417
+Epoch 19000 : Training Cost: 325074400.0 a,b,c,d,e,f: 23.898485 -197.18741 263.12512 2058.6716 6649.8037 16543.95
+Epoch 20000 : Training Cost: 301073570.0 a,b,c,d,e,f: 24.593851 -206.10497 272.72385 2137.1797 6898.544 17209.367
+Epoch 21000 : Training Cost: 279727000.0 a,b,c,d,e,f: 25.262104 -214.69217 282.14642 2212.6372 7135.217 17842.854
+Epoch 22000 : Training Cost: 260845550.0 a,b,c,d,e,f: 25.903376 -222.94969 291.4003 2284.9844 7359.4644 18442.408
+Epoch 23000 : Training Cost: 244218030.0 a,b,c,d,e,f: 26.517094 -230.8697 300.45532 2354.3003 7571.261 19007.49
+Epoch 24000 : Training Cost: 229660080.0 a,b,c,d,e,f: 27.102589 -238.44817 309.35342 2420.4185 7770.5728 19536.19
+Epoch 25000 : Training Cost: 216972400.0 a,b,c,d,e,f: 27.660324 -245.69016 318.10062 2483.3608 7957.354 20027.707
216972400.0 27.660324 -245.69016 318.10062 2483.3608 7957.354 20027.707
[
- {
- "tokens": ["Tell","me","about","the","drug","Aspirin","."],
- "labels": ["NONE","NONE","NONE","NONE","NONE","COMPOUND","NONE"]
- },
- {
- "tokens": ["Please","tell","me","information","about","the","compound","salicylic","acid","."],
- "labels": ["NONE","NONE","NONE","NONE","NONE","NONE","NONE","COMPOUND","COMPOUND","NONE"]
- },
- {
- "tokens": ["Information","about","the","compound","Ibuprofen","please","."],
- "labels": ["NONE","NONE","NONE","NONE","COMPOUND","NONE","NONE"]
- }
-]
+
[
+ {
+ "tokens": ["Tell","me","about","the","drug","Aspirin","."],
+ "labels": ["NONE","NONE","NONE","NONE","NONE","COMPOUND","NONE"]
+ },
+ {
+ "tokens": ["Please","tell","me","information","about","the","compound","salicylic","acid","."],
+ "labels": ["NONE","NONE","NONE","NONE","NONE","NONE","NONE","COMPOUND","COMPOUND","NONE"]
+ },
+ {
+ "tokens": ["Information","about","the","compound","Ibuprofen","please","."],
+ "labels": ["NONE","NONE","NONE","NONE","COMPOUND","NONE","NONE"]
+ }
+]
Phase 1
joxxxn@jupyter-nxxh6xx8:~/lab2-bomblab-navanchauhan/bombbomb$ gdb -ex 'break phase_1' -ex 'break explode_bomb' -ex 'run' ./bomb
-GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
-Copyright (C) 2022 Free Software Foundation, Inc.
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
-This is free software: you are free to change and redistribute it.
-There is NO WARRANTY, to the extent permitted by law.
-Type "show copying" and "show warranty" for details.
-This GDB was configured as "x86_64-linux-gnu".
-Type "show configuration" for configuration details.
-For bug reporting instructions, please see:
+
joxxxn@jupyter-nxxh6xx8:~/lab2-bomblab-navanchauhan/bombbomb$ gdb -ex 'break phase_1' -ex 'break explode_bomb' -ex 'run' ./bomb
+GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
+Copyright (C) 2022 Free Software Foundation, Inc.
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+Type "show copying" and "show warranty" for details.
+This GDB was configured as "x86_64-linux-gnu".
+Type "show configuration" for configuration details.
+For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
-Find the GDB manual and other documentation resources online at:
- <http://www.gnu.org/software/gdb/documentation/>.
-
-For help, type "help".
-Type "apropos word" to search for commands related to "word"...
-Reading symbols from ./bomb...
-Breakpoint 1 at 0x15c7
-Breakpoint 2 at 0x1d4a
-Starting program: /home/joxxxn/lab2-bomblab-navanchauhan/bombbomb/bomb
-[Thread debugging using libthread_db enabled]
-Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
-Welcome to my fiendish little bomb. You have 6 phases with
-which to blow yourself up. Have a nice day!
-test string
-
-Breakpoint 1, 0x00005555555555c7 in phase_1 ()
-(gdb) dias phase_1
-Undefined command: "dias". Try "help".
-(gdb) disas phase_1
-Dump of assembler code for function phase_1:
-=> 0x00005555555555c7 <+0>: endbr64
- 0x00005555555555cb <+4>: sub $0x8,%rsp
- 0x00005555555555cf <+8>: lea 0x1b7a(%rip),%rsi # 0x555555557150
- 0x00005555555555d6 <+15>: call 0x555555555b31 <strings_not_equal>
- 0x00005555555555db <+20>: test %eax,%eax
- 0x00005555555555dd <+22>: jne 0x5555555555e4 <phase_1+29>
- 0x00005555555555df <+24>: add $0x8,%rsp
- 0x00005555555555e3 <+28>: ret
- 0x00005555555555e4 <+29>: call 0x555555555d4a <explode_bomb>
- 0x00005555555555e9 <+34>: jmp 0x5555555555df <phase_1+24>
-End of assembler dump.
-(gdb) print 0x555555557150
-$1 = 93824992244048
-(gdb) x/1s 0x555555557150
-0x555555557150: "Controlling complexity is the essence of computer programming."
-(gdb)
+Find the GDB manual and other documentation resources online at:
+ <http://www.gnu.org/software/gdb/documentation/>.
+
+For help, type "help".
+Type "apropos word" to search for commands related to "word"...
+Reading symbols from ./bomb...
+Breakpoint 1 at 0x15c7
+Breakpoint 2 at 0x1d4a
+Starting program: /home/joxxxn/lab2-bomblab-navanchauhan/bombbomb/bomb
+[Thread debugging using libthread_db enabled]
+Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
+Welcome to my fiendish little bomb. You have 6 phases with
+which to blow yourself up. Have a nice day!
+test string
+
+Breakpoint 1, 0x00005555555555c7 in phase_1 ()
+(gdb) dias phase_1
+Undefined command: "dias". Try "help".
+(gdb) disas phase_1
+Dump of assembler code for function phase_1:
+=> 0x00005555555555c7 <+0>: endbr64
+ 0x00005555555555cb <+4>: sub $0x8,%rsp
+ 0x00005555555555cf <+8>: lea 0x1b7a(%rip),%rsi # 0x555555557150
+ 0x00005555555555d6 <+15>: call 0x555555555b31 <strings_not_equal>
+ 0x00005555555555db <+20>: test %eax,%eax
+ 0x00005555555555dd <+22>: jne 0x5555555555e4 <phase_1+29>
+ 0x00005555555555df <+24>: add $0x8,%rsp
+ 0x00005555555555e3 <+28>: ret
+ 0x00005555555555e4 <+29>: call 0x555555555d4a <explode_bomb>
+ 0x00005555555555e9 <+34>: jmp 0x5555555555df <phase_1+24>
+End of assembler dump.
+(gdb) print 0x555555557150
+$1 = 93824992244048
+(gdb) x/1s 0x555555557150
+0x555555557150: "Controlling complexity is the essence of computer programming."
+(gdb)
Phase 2
-Phase 1 defused. How about the next one?
-1 2 3 4 5 6
-
-Breakpoint 1, 0x00005555555555eb in phase_2 ()
-(gdb) disas
-Dump of assembler code for function phase_2:
-=> 0x00005555555555eb <+0>: endbr64
- 0x00005555555555ef <+4>: push %rbp
- 0x00005555555555f0 <+5>: push %rbx
- 0x00005555555555f1 <+6>: sub $0x28,%rsp
- 0x00005555555555f5 <+10>: mov %rsp,%rsi
- 0x00005555555555f8 <+13>: call 0x555555555d97 <read_six_numbers>
- 0x00005555555555fd <+18>: cmpl $0x0,(%rsp)
- 0x0000555555555601 <+22>: js 0x55555555560d <phase_2+34>
- 0x0000555555555603 <+24>: mov %rsp,%rbp
- 0x0000555555555606 <+27>: mov $0x1,%ebx
- 0x000055555555560b <+32>: jmp 0x555555555620 <phase_2+53>
- 0x000055555555560d <+34>: call 0x555555555d4a <explode_bomb>
- 0x0000555555555612 <+39>: jmp 0x555555555603 <phase_2+24>
- 0x0000555555555614 <+41>: add $0x1,%ebx
- 0x0000555555555617 <+44>: add $0x4,%rbp
- 0x000055555555561b <+48>: cmp $0x6,%ebx
- 0x000055555555561e <+51>: je 0x555555555631 <phase_2+70>
- 0x0000555555555620 <+53>: mov %ebx,%eax
- 0x0000555555555622 <+55>: add 0x0(%rbp),%eax
- 0x0000555555555625 <+58>: cmp %eax,0x4(%rbp)
- 0x0000555555555628 <+61>: je 0x555555555614 <phase_2+41>
- 0x000055555555562a <+63>: call 0x555555555d4a <explode_bomb>
- 0x000055555555562f <+68>: jmp 0x555555555614 <phase_2+41>
- 0x0000555555555631 <+70>: add $0x28,%rsp
- 0x0000555555555635 <+74>: pop %rbx
- 0x0000555555555636 <+75>: pop %rbp
- 0x0000555555555637 <+76>: ret
-End of assembler dump.
-(gdb)
-
0x00005555555555fd <+18>: cmpl $0x0,(%rsp)
- 0x0000555555555601 <+22>: js 0x55555555560d <phase_2+34>
+
+Phase 1 defused. How about the next one?
+1 2 3 4 5 6
+
+Breakpoint 1, 0x00005555555555eb in phase_2 ()
+(gdb) disas
+Dump of assembler code for function phase_2:
+=> 0x00005555555555eb <+0>: endbr64
+ 0x00005555555555ef <+4>: push %rbp
+ 0x00005555555555f0 <+5>: push %rbx
+ 0x00005555555555f1 <+6>: sub $0x28,%rsp
+ 0x00005555555555f5 <+10>: mov %rsp,%rsi
+ 0x00005555555555f8 <+13>: call 0x555555555d97 <read_six_numbers>
+ 0x00005555555555fd <+18>: cmpl $0x0,(%rsp)
+ 0x0000555555555601 <+22>: js 0x55555555560d <phase_2+34>
+ 0x0000555555555603 <+24>: mov %rsp,%rbp
+ 0x0000555555555606 <+27>: mov $0x1,%ebx
+ 0x000055555555560b <+32>: jmp 0x555555555620 <phase_2+53>
+ 0x000055555555560d <+34>: call 0x555555555d4a <explode_bomb>
+ 0x0000555555555612 <+39>: jmp 0x555555555603 <phase_2+24>
+ 0x0000555555555614 <+41>: add $0x1,%ebx
+ 0x0000555555555617 <+44>: add $0x4,%rbp
+ 0x000055555555561b <+48>: cmp $0x6,%ebx
+ 0x000055555555561e <+51>: je 0x555555555631 <phase_2+70>
+ 0x0000555555555620 <+53>: mov %ebx,%eax
+ 0x0000555555555622 <+55>: add 0x0(%rbp),%eax
+ 0x0000555555555625 <+58>: cmp %eax,0x4(%rbp)
+ 0x0000555555555628 <+61>: je 0x555555555614 <phase_2+41>
+ 0x000055555555562a <+63>: call 0x555555555d4a <explode_bomb>
+ 0x000055555555562f <+68>: jmp 0x555555555614 <phase_2+41>
+ 0x0000555555555631 <+70>: add $0x28,%rsp
+ 0x0000555555555635 <+74>: pop %rbx
+ 0x0000555555555636 <+75>: pop %rbp
+ 0x0000555555555637 <+76>: ret
+End of assembler dump.
+(gdb)
+
0x00005555555555fd <+18>: cmpl $0x0,(%rsp)
+ 0x0000555555555601 <+22>: js 0x55555555560d <phase_2+34>
...
- 0x000055555555560d <+34>: call 0x555555555d4a <explode_bomb>
+ 0x000055555555560d <+34>: call 0x555555555d4a <explode_bomb>
cmpl
instruction returns a negative value. The js
instruction stands for jump if sign -> causing a jump to the specified address if the sign bit is set. This would result in the explode_bomb function being called.
-
- 0x0000555555555603 <+24>: mov %rsp,%rbp
- 0x0000555555555606 <+27>: mov $0x1,%ebx
-
The program first compares if the first number is not 0. If the number is not 0, then the cmpl
instruction returns a negative value. The js
instruction stands for jump if sign -> causing a jump to the specified address if the sign bit is set. This would result in the explode_bomb function being called.
0x0000555555555603 <+24>: mov %rsp,%rbp
+ 0x0000555555555606 <+27>: mov $0x1,%ebx
+
+%rsp
in x86-64 asm, is the stack pointer i.e. it points to the top of the current stack frame. Since the program just read six numbers, the top of the stack (%rsp
) contains the address of the first number.
By executing mov %rsp,%rbp
we are setting the base pointer (%rbp
) to point to this address.
Now, for the second instruction mov $0x1,%ebx
, we are initalising the %ebx
register with the value 1. Based on the assembly code, you can see that this is being used as a counter/index for the loop.
-
0x000055555555560b <+32>: jmp 0x555555555620 <phase_2+53>
-
- The program now jumps to
- 0x0000555555555620 <+53>: mov %ebx,%eax
- 0x0000555555555622 <+55>: add 0x0(%rbp),%eax
- 0x0000555555555625 <+58>: cmp %eax,0x4(%rbp)
- 0x0000555555555628 <+61>: je 0x555555555614 <phase_2+41>
-
Now, for the second instruction mov $0x1,%ebx
, we are initalising the %ebx
register with the value 1. Based on the assembly code, you can see that this is being used as a counter/index for the loop.
0x000055555555560b <+32>: jmp 0x555555555620 <phase_2+53>
+
+The program now jumps to
0x0000555555555620 <+53>: mov %ebx,%eax
+ 0x0000555555555622 <+55>: add 0x0(%rbp),%eax
+ 0x0000555555555625 <+58>: cmp %eax,0x4(%rbp)
+ 0x0000555555555628 <+61>: je 0x555555555614 <phase_2+41>
+
+Here, the value from %ebx
is copied to the %eax
register. For this iteration, the value should be 1.
cmp %eax,0x4(%rbp)
- The instruction compares the value in %eax to the value at the memory address %rbp + 4
. Since Integers in this context are stored using a word of memory of 4 bytes, this indicates it checks against the second number in the sequence.
je 0x555555555614 <phase_2+41>
- The program will jump to phase_2+41
if the previous cmp
instruction determined the values as equal.
-
0x0000555555555614 <+41>: add $0x1,%ebx
- 0x0000555555555617 <+44>: add $0x4,%rbp
- 0x000055555555561b <+48>: cmp $0x6,%ebx
- 0x000055555555561e <+51>: je 0x555555555631 <phase2+70>
- 0x0000555555555620 <+53>: mov %ebx,%eax
- 0x0000555555555622 <+55>: add 0x0(%rbp),%eax
- 0x0000555555555625 <+58>: cmp %eax,0x4(%rbp)
- 0x0000555555555628 <+61>: je 0x555555555614 <phase2+41>
-
- je 0x555555555614 <phase_2+41>
- The program will jump to phase_2+41
if the previous cmp
instruction determined the values as equal.
0x0000555555555614 <+41>: add $0x1,%ebx
+ 0x0000555555555617 <+44>: add $0x4,%rbp
+ 0x000055555555561b <+48>: cmp $0x6,%ebx
+ 0x000055555555561e <+51>: je 0x555555555631 <phase_2+70>
+ 0x0000555555555620 <+53>: mov %ebx,%eax
+ 0x0000555555555622 <+55>: add 0x0(%rbp),%eax
+ 0x0000555555555625 <+58>: cmp %eax,0x4(%rbp)
+ 0x0000555555555628 <+61>: je 0x555555555614 <phase_2+41>
+
+Here, we can see that the program increments %ebx
by 1, adds a 4 byte offset to %rbp
(the number we will be matching now), and checks if %ebx
is equal to 6. If it is, it breaks the loop and jumps to <phase_2+70>
succesfully finishing this stage.
...
-Phase 1 defused. How about the next one?
-0 1 3 6 10 15
+Phase 1 defused. How about the next one?
+0 1 3 6 10 15
-Breakpoint 1, 0x00005555555555eb in phase_2 ()
-(gdb) continue
+Breakpoint 1, 0x00005555555555eb in phase_2 ()
+(gdb) continue
Continuing.
-That's number 2. Keep going!
+That's number 2. Keep going!
Let us look at the disassembled code first
0000000000001638 <phase_3>:
- 1638: f3 0f 1e fa endbr64
- 163c: 48 83 ec 18 sub $0x18,%rsp
- 1640: 48 8d 4c 24 07 lea 0x7(%rsp),%rcx
- 1645: 48 8d 54 24 0c lea 0xc(%rsp),%rdx
- 164a: 4c 8d 44 24 08 lea 0x8(%rsp),%r8
- 164f: 48 8d 35 60 1b 00 00 lea 0x1b60(%rip),%rsi # 31b6 <_IO_stdin_used+0x1b6>
- 1656: b8 00 00 00 00 mov $0x0,%eax
- 165b: e8 80 fc ff ff call 12e0 <__isoc99_sscanf@plt>
- 1660: 83 f8 02 cmp $0x2,%eax
- 1663: 7e 20 jle 1685 <phase_3+0x4d>
- 1665: 83 7c 24 0c 07 cmpl $0x7,0xc(%rsp)
- 166a: 0f 87 0d 01 00 00 ja 177d <phase_3+0x145>
- 1670: 8b 44 24 0c mov 0xc(%rsp),%eax
- 1674: 48 8d 15 55 1b 00 00 lea 0x1b55(%rip),%rdx # 31d0 <_IO_stdin_used+0x1d0>
- 167b: 48 63 04 82 movslq (%rdx,%rax,4),%rax
- 167f: 48 01 d0 add %rdx,%rax
- 1682: 3e ff e0 notrack jmp *%rax
- 1685: e8 c0 06 00 00 call 1d4a <explode_bomb>
- 168a: eb d9 jmp 1665 <phase_3+0x2d>
- 168c: b8 63 00 00 00 mov $0x63,%eax
- 1691: 81 7c 24 08 3d 02 00 cmpl $0x23d,0x8(%rsp)
- 1698: 00
- 1699: 0f 84 e8 00 00 00 je 1787 <phase_3+0x14f>
- 169f: e8 a6 06 00 00 call 1d4a <explode_bomb>
- 16a4: b8 63 00 00 00 mov $0x63,%eax
- 16a9: e9 d9 00 00 00 jmp 1787 <phase_3+0x14f>
- 16ae: b8 61 00 00 00 mov $0x61,%eax
- 16b3: 81 7c 24 08 27 01 00 cmpl $0x127,0x8(%rsp)
- 16ba: 00
- 16bb: 0f 84 c6 00 00 00 je 1787 <phase_3+0x14f>
- 16c1: e8 84 06 00 00 call 1d4a <explode_bomb>
- 16c6: b8 61 00 00 00 mov $0x61,%eax
- 16cb: e9 b7 00 00 00 jmp 1787 <phase_3+0x14f>
- 16d0: b8 78 00 00 00 mov $0x78,%eax
- 16d5: 81 7c 24 08 e7 02 00 cmpl $0x2e7,0x8(%rsp)
- 16dc: 00
- 16dd: 0f 84 a4 00 00 00 je 1787 <phase_3+0x14f>
- 16e3: e8 62 06 00 00 call 1d4a <explode_bomb>
- 16e8: b8 78 00 00 00 mov $0x78,%eax
- 16ed: e9 95 00 00 00 jmp 1787 <phase_3+0x14f>
- 16f2: b8 64 00 00 00 mov $0x64,%eax
- 16f7: 81 7c 24 08 80 02 00 cmpl $0x280,0x8(%rsp)
- 16fe: 00
- 16ff: 0f 84 82 00 00 00 je 1787 <phase_3+0x14f>
- 1705: e8 40 06 00 00 call 1d4a <explode_bomb>
- 170a: b8 64 00 00 00 mov $0x64,%eax
- 170f: eb 76 jmp 1787 <phase_3+0x14f>
- 1711: b8 6d 00 00 00 mov $0x6d,%eax
- 1716: 81 7c 24 08 ff 02 00 cmpl $0x2ff,0x8(%rsp)
- 171d: 00
- 171e: 74 67 je 1787 <phase_3+0x14f>
- 1720: e8 25 06 00 00 call 1d4a <explode_bomb>
- 1725: b8 6d 00 00 00 mov $0x6d,%eax
- 172a: eb 5b jmp 1787 <phase_3+0x14f>
- 172c: b8 71 00 00 00 mov $0x71,%eax
- 1731: 81 7c 24 08 75 03 00 cmpl $0x375,0x8(%rsp)
- 1738: 00
- 1739: 74 4c je 1787 <phase_3+0x14f>
- 173b: e8 0a 06 00 00 call 1d4a <explode_bomb>
- 1740: b8 71 00 00 00 mov $0x71,%eax
- 1745: eb 40 jmp 1787 <phase_3+0x14f>
- 1747: b8 79 00 00 00 mov $0x79,%eax
- 174c: 81 7c 24 08 94 02 00 cmpl $0x294,0x8(%rsp)
- 1753: 00
- 1754: 74 31 je 1787 <phase_3+0x14f>
- 1756: e8 ef 05 00 00 call 1d4a <explode_bomb>
- 175b: b8 79 00 00 00 mov $0x79,%eax
- 1760: eb 25 jmp 1787 <phase_3+0x14f>
- 1762: b8 79 00 00 00 mov $0x79,%eax
- 1767: 81 7c 24 08 88 02 00 cmpl $0x288,0x8(%rsp)
- 176e: 00
- 176f: 74 16 je 1787 <phase_3+0x14f>
- 1771: e8 d4 05 00 00 call 1d4a <explode_bomb>
- 1776: b8 79 00 00 00 mov $0x79,%eax
- 177b: eb 0a jmp 1787 <phase_3+0x14f>
- 177d: e8 c8 05 00 00 call 1d4a <explode_bomb>
- 1782: b8 68 00 00 00 mov $0x68,%eax
- 1787: 38 44 24 07 cmp %al,0x7(%rsp)
- 178b: 75 05 jne 1792 <phase_3+0x15a>
- 178d: 48 83 c4 18 add $0x18,%rsp
- 1791: c3 ret
- 1792: e8 b3 05 00 00 call 1d4a <explode_bomb>
- 1797: eb f4 jmp 178d <phase_3+0x155>
+0000000000001638 <phase_3>:
+ 1638: f3 0f 1e fa endbr64
+ 163c: 48 83 ec 18 sub $0x18,%rsp
+ 1640: 48 8d 4c 24 07 lea 0x7(%rsp),%rcx
+ 1645: 48 8d 54 24 0c lea 0xc(%rsp),%rdx
+ 164a: 4c 8d 44 24 08 lea 0x8(%rsp),%r8
+ 164f: 48 8d 35 60 1b 00 00 lea 0x1b60(%rip),%rsi # 31b6 <_IO_stdin_used+0x1b6>
+ 1656: b8 00 00 00 00 mov $0x0,%eax
+ 165b: e8 80 fc ff ff call 12e0 <__isoc99_sscanf@plt>
+ 1660: 83 f8 02 cmp $0x2,%eax
+ 1663: 7e 20 jle 1685 <phase_3+0x4d>
+ 1665: 83 7c 24 0c 07 cmpl $0x7,0xc(%rsp)
+ 166a: 0f 87 0d 01 00 00 ja 177d <phase_3+0x145>
+ 1670: 8b 44 24 0c mov 0xc(%rsp),%eax
+ 1674: 48 8d 15 55 1b 00 00 lea 0x1b55(%rip),%rdx # 31d0 <_IO_stdin_used+0x1d0>
+ 167b: 48 63 04 82 movslq (%rdx,%rax,4),%rax
+ 167f: 48 01 d0 add %rdx,%rax
+ 1682: 3e ff e0 notrack jmp *%rax
+ 1685: e8 c0 06 00 00 call 1d4a <explode_bomb>
+ 168a: eb d9 jmp 1665 <phase_3+0x2d>
+ 168c: b8 63 00 00 00 mov $0x63,%eax
+ 1691: 81 7c 24 08 3d 02 00 cmpl $0x23d,0x8(%rsp)
+ 1698: 00
+ 1699: 0f 84 e8 00 00 00 je 1787 <phase_3+0x14f>
+ 169f: e8 a6 06 00 00 call 1d4a <explode_bomb>
+ 16a4: b8 63 00 00 00 mov $0x63,%eax
+ 16a9: e9 d9 00 00 00 jmp 1787 <phase_3+0x14f>
+ 16ae: b8 61 00 00 00 mov $0x61,%eax
+ 16b3: 81 7c 24 08 27 01 00 cmpl $0x127,0x8(%rsp)
+ 16ba: 00
+ 16bb: 0f 84 c6 00 00 00 je 1787 <phase_3+0x14f>
+ 16c1: e8 84 06 00 00 call 1d4a <explode_bomb>
+ 16c6: b8 61 00 00 00 mov $0x61,%eax
+ 16cb: e9 b7 00 00 00 jmp 1787 <phase_3+0x14f>
+ 16d0: b8 78 00 00 00 mov $0x78,%eax
+ 16d5: 81 7c 24 08 e7 02 00 cmpl $0x2e7,0x8(%rsp)
+ 16dc: 00
+ 16dd: 0f 84 a4 00 00 00 je 1787 <phase_3+0x14f>
+ 16e3: e8 62 06 00 00 call 1d4a <explode_bomb>
+ 16e8: b8 78 00 00 00 mov $0x78,%eax
+ 16ed: e9 95 00 00 00 jmp 1787 <phase_3+0x14f>
+ 16f2: b8 64 00 00 00 mov $0x64,%eax
+ 16f7: 81 7c 24 08 80 02 00 cmpl $0x280,0x8(%rsp)
+ 16fe: 00
+ 16ff: 0f 84 82 00 00 00 je 1787 <phase_3+0x14f>
+ 1705: e8 40 06 00 00 call 1d4a <explode_bomb>
+ 170a: b8 64 00 00 00 mov $0x64,%eax
+ 170f: eb 76 jmp 1787 <phase_3+0x14f>
+ 1711: b8 6d 00 00 00 mov $0x6d,%eax
+ 1716: 81 7c 24 08 ff 02 00 cmpl $0x2ff,0x8(%rsp)
+ 171d: 00
+ 171e: 74 67 je 1787 <phase_3+0x14f>
+ 1720: e8 25 06 00 00 call 1d4a <explode_bomb>
+ 1725: b8 6d 00 00 00 mov $0x6d,%eax
+ 172a: eb 5b jmp 1787 <phase_3+0x14f>
+ 172c: b8 71 00 00 00 mov $0x71,%eax
+ 1731: 81 7c 24 08 75 03 00 cmpl $0x375,0x8(%rsp)
+ 1738: 00
+ 1739: 74 4c je 1787 <phase_3+0x14f>
+ 173b: e8 0a 06 00 00 call 1d4a <explode_bomb>
+ 1740: b8 71 00 00 00 mov $0x71,%eax
+ 1745: eb 40 jmp 1787 <phase_3+0x14f>
+ 1747: b8 79 00 00 00 mov $0x79,%eax
+ 174c: 81 7c 24 08 94 02 00 cmpl $0x294,0x8(%rsp)
+ 1753: 00
+ 1754: 74 31 je 1787 <phase_3+0x14f>
+ 1756: e8 ef 05 00 00 call 1d4a <explode_bomb>
+ 175b: b8 79 00 00 00 mov $0x79,%eax
+ 1760: eb 25 jmp 1787 <phase_3+0x14f>
+ 1762: b8 79 00 00 00 mov $0x79,%eax
+ 1767: 81 7c 24 08 88 02 00 cmpl $0x288,0x8(%rsp)
+ 176e: 00
+ 176f: 74 16 je 1787 <phase_3+0x14f>
+ 1771: e8 d4 05 00 00 call 1d4a <explode_bomb>
+ 1776: b8 79 00 00 00 mov $0x79,%eax
+ 177b: eb 0a jmp 1787 <phase_3+0x14f>
+ 177d: e8 c8 05 00 00 call 1d4a <explode_bomb>
+ 1782: b8 68 00 00 00 mov $0x68,%eax
+ 1787: 38 44 24 07 cmp %al,0x7(%rsp)
+ 178b: 75 05 jne 1792 <phase_3+0x15a>
+ 178d: 48 83 c4 18 add $0x18,%rsp
+ 1791: c3 ret
+ 1792: e8 b3 05 00 00 call 1d4a <explode_bomb>
+ 1797: eb f4 jmp 178d <phase_3+0x155>
...
- 165b: e8 80 fc ff ff call 12e0 <__isoc99_sscanf@plt>
+ 165b: e8 80 fc ff ff call 12e0 <__isoc99_sscanf@plt>
...
Because I do not want to enter the solutions to phases 1 and 2 again and again, I am goig to pass a file which has these solutions.
joxxxn@jupyter-nxxh6xx8:~/lab2-bomblab-navanchauhan/bombbomb$ gdb -ex 'break phase_3' -ex 'break explode_bomb' -ex 'run' -args ./bomb sol.txt
-GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
-Copyright (C) 2022 Free Software Foundation, Inc.
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
-This is free software: you are free to change and redistribute it.
-There is NO WARRANTY, to the extent permitted by law.
-Type "show copying" and "show warranty" for details.
-This GDB was configured as "x86_64-linux-gnu".
-Type "show configuration" for configuration details.
-For bug reporting instructions, please see:
+joxxxn@jupyter-nxxh6xx8:~/lab2-bomblab-navanchauhan/bombbomb$ gdb -ex 'break phase_3' -ex 'break explode_bomb' -ex 'run' -args ./bomb sol.txt
+GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
+Copyright (C) 2022 Free Software Foundation, Inc.
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+Type "show copying" and "show warranty" for details.
+This GDB was configured as "x86_64-linux-gnu".
+Type "show configuration" for configuration details.
+For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
-Find the GDB manual and other documentation resources online at:
- <http://www.gnu.org/software/gdb/documentation/>.
-
-For help, type "help".
-Type "apropos word" to search for commands related to "word"...
-Reading symbols from ./bomb...
-Breakpoint 1 at 0x1638
-Breakpoint 2 at 0x1d4a
-Starting program: /home/joxxxn/lab2-bomblab-navanchauhan/bombbomb/bomb sol.txt
-[Thread debugging using libthread_db enabled]
-Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
-Welcome to my fiendish little bomb. You have 6 phases with
-which to blow yourself up. Have a nice day!
-Phase 1 defused. How about the next one?
-That's number 2. Keep going!
-random string
-
-Breakpoint 1, 0x0000555555555638 in phase_3 ()
-(gdb) disas
-Dump of assembler code for function phase_3:
-=> 0x0000555555555638 <+0>: endbr64
- 0x000055555555563c <+4>: sub $0x18,%rsp
- 0x0000555555555640 <+8>: lea 0x7(%rsp),%rcx
- 0x0000555555555645 <+13>: lea 0xc(%rsp),%rdx
- 0x000055555555564a <+18>: lea 0x8(%rsp),%r8
- 0x000055555555564f <+23>: lea 0x1b60(%rip),%rsi # 0x5555555571b6
- 0x0000555555555656 <+30>: mov $0x0,%eax
- 0x000055555555565b <+35>: call 0x5555555552e0 <__isoc99_sscanf@plt>
- 0x0000555555555660 <+40>: cmp $0x2,%eax
- 0x0000555555555663 <+43>: jle 0x555555555685 <phase_3+77>
- 0x0000555555555665 <+45>: cmpl $0x7,0xc(%rsp)
- 0x000055555555566a <+50>: ja 0x55555555577d <phase_3+325>
- 0x0000555555555670 <+56>: mov 0xc(%rsp),%eax
- 0x0000555555555674 <+60>: lea 0x1b55(%rip),%rdx # 0x5555555571d0
- 0x000055555555567b <+67>: movslq (%rdx,%rax,4),%rax
- 0x000055555555567f <+71>: add %rdx,%rax
- 0x0000555555555682 <+74>: notrack jmp *%rax
- 0x0000555555555685 <+77>: call 0x555555555d4a <explode_bomb>
- 0x000055555555568a <+82>: jmp 0x555555555665 <phase_3+45>
- 0x000055555555568c <+84>: mov $0x63,%eax
- 0x0000555555555691 <+89>: cmpl $0x23d,0x8(%rsp)
- 0x0000555555555699 <+97>: je 0x555555555787 <phase_3+335>
- 0x000055555555569f <+103>: call 0x555555555d4a <explode_bomb>
- 0x00005555555556a4 <+108>: mov $0x63,%eax
- 0x00005555555556a9 <+113>: jmp 0x555555555787 <phase_3+335>
---Type <RET> for more, q to quit, c to continue without paging--
+Find the GDB manual and other documentation resources online at:
+ <http://www.gnu.org/software/gdb/documentation/>.
+
+For help, type "help".
+Type "apropos word" to search for commands related to "word"...
+Reading symbols from ./bomb...
+Breakpoint 1 at 0x1638
+Breakpoint 2 at 0x1d4a
+Starting program: /home/joxxxn/lab2-bomblab-navanchauhan/bombbomb/bomb sol.txt
+[Thread debugging using libthread_db enabled]
+Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
+Welcome to my fiendish little bomb. You have 6 phases with
+which to blow yourself up. Have a nice day!
+Phase 1 defused. How about the next one?
+That's number 2. Keep going!
+random string
+
+Breakpoint 1, 0x0000555555555638 in phase_3 ()
+(gdb) disas
+Dump of assembler code for function phase_3:
+=> 0x0000555555555638 <+0>: endbr64
+ 0x000055555555563c <+4>: sub $0x18,%rsp
+ 0x0000555555555640 <+8>: lea 0x7(%rsp),%rcx
+ 0x0000555555555645 <+13>: lea 0xc(%rsp),%rdx
+ 0x000055555555564a <+18>: lea 0x8(%rsp),%r8
+ 0x000055555555564f <+23>: lea 0x1b60(%rip),%rsi # 0x5555555571b6
+ 0x0000555555555656 <+30>: mov $0x0,%eax
+ 0x000055555555565b <+35>: call 0x5555555552e0 <__isoc99_sscanf@plt>
+ 0x0000555555555660 <+40>: cmp $0x2,%eax
+ 0x0000555555555663 <+43>: jle 0x555555555685 <phase_3+77>
+ 0x0000555555555665 <+45>: cmpl $0x7,0xc(%rsp)
+ 0x000055555555566a <+50>: ja 0x55555555577d <phase_3+325>
+ 0x0000555555555670 <+56>: mov 0xc(%rsp),%eax
+ 0x0000555555555674 <+60>: lea 0x1b55(%rip),%rdx # 0x5555555571d0
+ 0x000055555555567b <+67>: movslq (%rdx,%rax,4),%rax
+ 0x000055555555567f <+71>: add %rdx,%rax
+ 0x0000555555555682 <+74>: notrack jmp *%rax
+ 0x0000555555555685 <+77>: call 0x555555555d4a <explode_bomb>
+ 0x000055555555568a <+82>: jmp 0x555555555665 <phase_3+45>
+ 0x000055555555568c <+84>: mov $0x63,%eax
+ 0x0000555555555691 <+89>: cmpl $0x23d,0x8(%rsp)
+ 0x0000555555555699 <+97>: je 0x555555555787 <phase_3+335>
+ 0x000055555555569f <+103>: call 0x555555555d4a <explode_bomb>
+ 0x00005555555556a4 <+108>: mov $0x63,%eax
+ 0x00005555555556a9 <+113>: jmp 0x555555555787 <phase_3+335>
+--Type <RET> for more, q to quit, c to continue without paging--
gdb
has thankfully marked the address which is being passed to scanf
. We can access the value:
(gdb) x/1s 0x5555555571b6
-0x5555555571b6: "%d %c %d"
-(gdb)
+(gdb) x/1s 0x5555555571b6
+0x5555555571b6: "%d %c %d"
+(gdb)
BINGO! The program expects an integer, character, and another integer. Onwards.
0x0000555555555660 <+40>: cmp $0x2,%eax
- 0x0000555555555663 <+43>: jle 0x555555555685 <phase_3+77>
+ 0x0000555555555660 <+40>: cmp $0x2,%eax
+ 0x0000555555555663 <+43>: jle 0x555555555685 <phase_3+77>
...
- 0x0000555555555685 <+77>: call 0x555555555d4a <explode_bomb>
+ 0x0000555555555685 <+77>: call 0x555555555d4a <explode_bomb>
scanf
returns the number of fields that were succesfully converted and assigned
0x0000555555555665 <+45>: cmpl $0x7,0xc(%rsp)
- 0x000055555555566a <+50>: ja 0x55555555577d <phase_3+325>
+ 0x0000555555555665 <+45>: cmpl $0x7,0xc(%rsp)
+ 0x000055555555566a <+50>: ja 0x55555555577d <phase_3+325>
...
- 0x000055555555577d <+325>: call 0x555555555d4a <explode_bomb>
+ 0x000055555555577d <+325>: call 0x555555555d4a <explode_bomb>
Similarly, the program checks and ensures the returned value is not > 7. -
0x0000555555555670 <+56>: mov 0xc(%rsp),%eax
- 0x0000555555555674 <+60>: lea 0x1b55(%rip),%rdx # 0x5555555571d0
- 0x000055555555567b <+67>: movslq (%rdx,%rax,4),%rax
- 0x000055555555567f <+71>: add %rdx,%rax
- 0x0000555555555682 <+74>: notrack jmp *%rax
- 0x0000555555555685 <+77>: call 0x555555555d4a <explode_bomb>
-
- Similarly, the program checks and ensures the returned value is not > 7.
+ + 0x0000555555555670 <+56>: mov 0xc(%rsp),%eax
+ 0x0000555555555674 <+60>: lea 0x1b55(%rip),%rdx # 0x5555555571d0
+ 0x000055555555567b <+67>: movslq (%rdx,%rax,4),%rax
+ 0x000055555555567f <+71>: add %rdx,%rax
+ 0x0000555555555682 <+74>: notrack jmp *%rax
+ 0x0000555555555685 <+77>: call 0x555555555d4a <explode_bomb>
+
+0x0000555555555670 <+56>: mov 0xc(%rsp),%eax
- Moves value located at 0xc
(12 in Decimal) bytes above the stack pointer to %eax
register. We can see that this makes us jump to <phase_3+186>
(Continue to step through the code by using ni
)
-
0x00005555555556f2 <+186>: mov $0x64,%eax
- 0x00005555555556f7 <+191>: cmpl $0x280,0x8(%rsp)
- 0x00005555555556ff <+199>: je 0x555555555787 <phase3+335>
- 0x0000555555555705 <+205>: call 0x555555555d4a <explodebomb>
-
- We see that 0x64
(Decimal 100) is being stored in %eax
. Then, the program compares 0x280
(Decimal 640) with memory address 0x8
bytes above the stack pointer (%rsp
). If the values are equal, then it jumps to <phase_3+335>
, otherwise explode_bomb
is called.
-
0x0000555555555787 <+335>: cmp %al,0x7(%rsp)
- 0x000055555555578b <+339>: jne 0x555555555792 <phase3+346>
- 0x000055555555578d <+341>: add $0x18,%rsp
- 0x0000555555555791 <+345>: ret
- 0x0000555555555792 <+346>: call 0x555555555d4a <explodebomb>
-
- We can see that this makes us jump to <phase_3+186>
(Continue to step through the code by using ni
)
0x00005555555556f2 <+186>: mov $0x64,%eax
+ 0x00005555555556f7 <+191>: cmpl $0x280,0x8(%rsp)
+ 0x00005555555556ff <+199>: je 0x555555555787 <phase_3+335>
+ 0x0000555555555705 <+205>: call 0x555555555d4a <explode_bomb>
+
+We see that 0x64
(Decimal 100) is being stored in %eax
. Then, the program compares 0x280
(Decimal 640) with memory address 0x8
bytes above the stack pointer (%rsp
). If the values are equal, then it jumps to <phase_3+335>
, otherwise explode_bomb
is called.
0x0000555555555787 <+335>: cmp %al,0x7(%rsp)
+ 0x000055555555578b <+339>: jne 0x555555555792 <phase_3+346>
+ 0x000055555555578d <+341>: add $0x18,%rsp
+ 0x0000555555555791 <+345>: ret
+ 0x0000555555555792 <+346>: call 0x555555555d4a <explode_bomb>
+
+Here, the program is comparing the value of our given character to the value stored in %al
(lower 8 bits of EAX
), and checks if they are not equal.
Knowing that the character is stored at an offset of 7 bytes to %rsp
, we can print and check the value by running:
(gdb) x/1cw $rsp+7
+(gdb) x/1cw $rsp+7
c
-(gdb) print $al
-$1 = 100
+(gdb) print $al
+$1 = 100
...
-That's number 2. Keep going!
-3 d 640
+That's number 2. Keep going!
+3 d 640
-Breakpoint 1, 0x0000555555555638 in phase_3 ()
-(gdb) continue
+Breakpoint 1, 0x0000555555555638 in phase_3 ()
+(gdb) continue
Continuing.
-Halfway there!
+Halfway there!
joxxxn@jupyter-nxxh6xx8:~/lab2-bomblab-navanchauhan/bombbomb$ gdb -ex 'break phase_4' -ex 'break explode_bomb' -ex 'run' -args ./bomb sol.txt
-GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
-Copyright (C) 2022 Free Software Foundation, Inc.
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
-This is free software: you are free to change and redistribute it.
-There is NO WARRANTY, to the extent permitted by law.
-Type "show copying" and "show warranty" for details.
-This GDB was configured as "x86_64-linux-gnu".
-Type "show configuration" for configuration details.
-For bug reporting instructions, please see:
+joxxxn@jupyter-nxxh6xx8:~/lab2-bomblab-navanchauhan/bombbomb$ gdb -ex 'break phase_4' -ex 'break explode_bomb' -ex 'run' -args ./bomb sol.txt
+GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
+Copyright (C) 2022 Free Software Foundation, Inc.
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+Type "show copying" and "show warranty" for details.
+This GDB was configured as "x86_64-linux-gnu".
+Type "show configuration" for configuration details.
+For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
-Find the GDB manual and other documentation resources online at:
- <http://www.gnu.org/software/gdb/documentation/>.
-
-For help, type "help".
-Type "apropos word" to search for commands related to "word"...
-Reading symbols from ./bomb...
-Breakpoint 1 at 0x17d3
-Breakpoint 2 at 0x1d4a
-Starting program: /home/joxxxn/lab2-bomblab-navanchauhan/bombbomb/bomb sol.txt
-[Thread debugging using libthread_db enabled]
-Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
-Welcome to my fiendish little bomb. You have 6 phases with
-which to blow yourself up. Have a nice day!
-Phase 1 defused. How about the next one?
-That's number 2. Keep going!
-Halfway there!
-test string
-
-Breakpoint 1, 0x00005555555557d3 in phase_4 ()
-(gdb) disas phase_4
-Dump of assembler code for function phase_4:
-=> 0x00005555555557d3 <+0>: endbr64
- 0x00005555555557d7 <+4>: sub $0x18,%rsp
- 0x00005555555557db <+8>: lea 0x8(%rsp),%rcx
- 0x00005555555557e0 <+13>: lea 0xc(%rsp),%rdx
- 0x00005555555557e5 <+18>: lea 0x1bba(%rip),%rsi # 0x5555555573a6
- 0x00005555555557ec <+25>: mov $0x0,%eax
- 0x00005555555557f1 <+30>: call 0x5555555552e0 <__isoc99_sscanf@plt>
- 0x00005555555557f6 <+35>: cmp $0x2,%eax
- 0x00005555555557f9 <+38>: jne 0x555555555802 <phase_4+47>
- 0x00005555555557fb <+40>: cmpl $0xe,0xc(%rsp)
- 0x0000555555555800 <+45>: jbe 0x555555555807 <phase_4+52>
- 0x0000555555555802 <+47>: call 0x555555555d4a <explode_bomb>
- 0x0000555555555807 <+52>: mov $0xe,%edx
- 0x000055555555580c <+57>: mov $0x0,%esi
- 0x0000555555555811 <+62>: mov 0xc(%rsp),%edi
- 0x0000555555555815 <+66>: call 0x555555555799 <func4>
- 0x000055555555581a <+71>: cmp $0x2,%eax
- 0x000055555555581d <+74>: jne 0x555555555826 <phase_4+83>
- 0x000055555555581f <+76>: cmpl $0x2,0x8(%rsp)
- 0x0000555555555824 <+81>: je 0x55555555582b <phase_4+88>
- 0x0000555555555826 <+83>: call 0x555555555d4a <explode_bomb>
- 0x000055555555582b <+88>: add $0x18,%rsp
- 0x000055555555582f <+92>: ret
-End of assembler dump.
-(gdb)
+Find the GDB manual and other documentation resources online at:
+ <http://www.gnu.org/software/gdb/documentation/>.
+
+For help, type "help".
+Type "apropos word" to search for commands related to "word"...
+Reading symbols from ./bomb...
+Breakpoint 1 at 0x17d3
+Breakpoint 2 at 0x1d4a
+Starting program: /home/joxxxn/lab2-bomblab-navanchauhan/bombbomb/bomb sol.txt
+[Thread debugging using libthread_db enabled]
+Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
+Welcome to my fiendish little bomb. You have 6 phases with
+which to blow yourself up. Have a nice day!
+Phase 1 defused. How about the next one?
+That's number 2. Keep going!
+Halfway there!
+test string
+
+Breakpoint 1, 0x00005555555557d3 in phase_4 ()
+(gdb) disas phase_4
+Dump of assembler code for function phase_4:
+=> 0x00005555555557d3 <+0>: endbr64
+ 0x00005555555557d7 <+4>: sub $0x18,%rsp
+ 0x00005555555557db <+8>: lea 0x8(%rsp),%rcx
+ 0x00005555555557e0 <+13>: lea 0xc(%rsp),%rdx
+ 0x00005555555557e5 <+18>: lea 0x1bba(%rip),%rsi # 0x5555555573a6
+ 0x00005555555557ec <+25>: mov $0x0,%eax
+ 0x00005555555557f1 <+30>: call 0x5555555552e0 <__isoc99_sscanf@plt>
+ 0x00005555555557f6 <+35>: cmp $0x2,%eax
+ 0x00005555555557f9 <+38>: jne 0x555555555802 <phase_4+47>
+ 0x00005555555557fb <+40>: cmpl $0xe,0xc(%rsp)
+ 0x0000555555555800 <+45>: jbe 0x555555555807 <phase_4+52>
+ 0x0000555555555802 <+47>: call 0x555555555d4a <explode_bomb>
+ 0x0000555555555807 <+52>: mov $0xe,%edx
+ 0x000055555555580c <+57>: mov $0x0,%esi
+ 0x0000555555555811 <+62>: mov 0xc(%rsp),%edi
+ 0x0000555555555815 <+66>: call 0x555555555799 <func4>
+ 0x000055555555581a <+71>: cmp $0x2,%eax
+ 0x000055555555581d <+74>: jne 0x555555555826 <phase_4+83>
+ 0x000055555555581f <+76>: cmpl $0x2,0x8(%rsp)
+ 0x0000555555555824 <+81>: je 0x55555555582b <phase_4+88>
+ 0x0000555555555826 <+83>: call 0x555555555d4a <explode_bomb>
+ 0x000055555555582b <+88>: add $0x18,%rsp
+ 0x000055555555582f <+92>: ret
+End of assembler dump.
+(gdb)
Again, gdb
has marked the string being passed to scanf
(gdb) x/1s 0x5555555573a6
-0x5555555573a6: "%d %d"
+(gdb) x/1s 0x5555555573a6
+0x5555555573a6: "%d %d"
Okay, so this time we are supposed to enter 2 numbers. -
0x00005555555557f6 <+35>: cmp $0x2,%eax
- 0x00005555555557f9 <+38>: jne 0x555555555802 <phase_4+47>
-
- Okay, so this time we are supposed to enter 2 numbers.
+ + 0x00005555555557f6 <+35>: cmp $0x2,%eax
+ 0x00005555555557f9 <+38>: jne 0x555555555802 <phase_4+47>
+
+Checks if there were 2 values read from calling scanf
, if not -> jump to <phase_4+47>
which calls <explode_bomb>
.
-
0x00005555555557fb <+40>: cmpl $0xe,0xc(%rsp)
- 0x0000555555555800 <+45>: jbe 0x555555555807 <phase_4+52>
-
- Checks if there were 2 values read from calling scanf
, if not -> jump to <phase_4+47>
which calls <explode_bomb>
.
0x00005555555557fb <+40>: cmpl $0xe,0xc(%rsp)
+ 0x0000555555555800 <+45>: jbe 0x555555555807 <phase_4+52>
+
+Compare 0xe
(14 in Decimal) and value stored at $rsp
+ 0xc
bytes (Decimal 12). If this condition is met (<= 14), jump to <phase_4+52>
. If not, then explode bomb.
...
- 0x0000555555555807 <+52>: mov $0xe,%edx
- 0x000055555555580c <+57>: mov $0x0,%esi
- 0x0000555555555811 <+62>: mov 0xc(%rsp),%edi
- 0x0000555555555815 <+66>: call 0x555555555799 <func4>
- 0x000055555555581a <+71>: cmp $0x2,%eax
- 0x000055555555581d <+74>: jne 0x555555555826 <phase_4+83>
- 0x000055555555581f <+76>: cmpl $0x2,0x8(%rsp)
- 0x0000555555555824 <+81>: je 0x55555555582b <phase_4+88>
- 0x0000555555555826 <+83>: call 0x555555555d4a <explode_bomb>
+ 0x0000555555555807 <+52>: mov $0xe,%edx
+ 0x000055555555580c <+57>: mov $0x0,%esi
+ 0x0000555555555811 <+62>: mov 0xc(%rsp),%edi
+ 0x0000555555555815 <+66>: call 0x555555555799 <func4>
+ 0x000055555555581a <+71>: cmp $0x2,%eax
+ 0x000055555555581d <+74>: jne 0x555555555826 <phase_4+83>
+ 0x000055555555581f <+76>: cmpl $0x2,0x8(%rsp)
+ 0x0000555555555824 <+81>: je 0x55555555582b <phase_4+88>
+ 0x0000555555555826 <+83>: call 0x555555555d4a <explode_bomb>
Let us look into func4
(gdb) disas func4
-Dump of assembler code for function func4:
- 0x0000555555555799 <+0>: endbr64
- 0x000055555555579d <+4>: sub $0x8,%rsp
- 0x00005555555557a1 <+8>: mov %edx,%ecx
- 0x00005555555557a3 <+10>: sub %esi,%ecx
- 0x00005555555557a5 <+12>: shr %ecx
- 0x00005555555557a7 <+14>: add %esi,%ecx
- 0x00005555555557a9 <+16>: cmp %edi,%ecx
- 0x00005555555557ab <+18>: ja 0x5555555557b9 <func4+32>
- 0x00005555555557ad <+20>: mov $0x0,%eax
- 0x00005555555557b2 <+25>: jb 0x5555555557c5 <func4+44>
- 0x00005555555557b4 <+27>: add $0x8,%rsp
- 0x00005555555557b8 <+31>: ret
- 0x00005555555557b9 <+32>: lea -0x1(%rcx),%edx
- 0x00005555555557bc <+35>: call 0x555555555799 <func4>
- 0x00005555555557c1 <+40>: add %eax,%eax
- 0x00005555555557c3 <+42>: jmp 0x5555555557b4 <func4+27>
- 0x00005555555557c5 <+44>: lea 0x1(%rcx),%esi
- 0x00005555555557c8 <+47>: call 0x555555555799 <func4>
- 0x00005555555557cd <+52>: lea 0x1(%rax,%rax,1),%eax
- 0x00005555555557d1 <+56>: jmp 0x5555555557b4 <func4+27>
+(gdb) disas func4
+Dump of assembler code for function func4:
+ 0x0000555555555799 <+0>: endbr64
+ 0x000055555555579d <+4>: sub $0x8,%rsp
+ 0x00005555555557a1 <+8>: mov %edx,%ecx
+ 0x00005555555557a3 <+10>: sub %esi,%ecx
+ 0x00005555555557a5 <+12>: shr %ecx
+ 0x00005555555557a7 <+14>: add %esi,%ecx
+ 0x00005555555557a9 <+16>: cmp %edi,%ecx
+ 0x00005555555557ab <+18>: ja 0x5555555557b9 <func4+32>
+ 0x00005555555557ad <+20>: mov $0x0,%eax
+ 0x00005555555557b2 <+25>: jb 0x5555555557c5 <func4+44>
+ 0x00005555555557b4 <+27>: add $0x8,%rsp
+ 0x00005555555557b8 <+31>: ret
+ 0x00005555555557b9 <+32>: lea -0x1(%rcx),%edx
+ 0x00005555555557bc <+35>: call 0x555555555799 <func4>
+ 0x00005555555557c1 <+40>: add %eax,%eax
+ 0x00005555555557c3 <+42>: jmp 0x5555555557b4 <func4+27>
+ 0x00005555555557c5 <+44>: lea 0x1(%rcx),%esi
+ 0x00005555555557c8 <+47>: call 0x555555555799 <func4>
+ 0x00005555555557cd <+52>: lea 0x1(%rax,%rax,1),%eax
+ 0x00005555555557d1 <+56>: jmp 0x5555555557b4 <func4+27>
endbr64
-sub $0x8,%rsp // subtract 8 bytes from the stack pointer
-mov %edx,%ecx // Move the value in register %edx to %ecx
-sub %esi,%ecx // Subtract the value in %esi from %ecx
-shr %ecx // Right shift the value in %ecx by one bit (dividing the value by 2)
-add %esi,%ecx // Add the value in %esi to %ecx
-cmp %edi,%ecx // Compare
-ja 0x5555555557b9 <func4+32> // If %ecx > %edi -> jump to instruction at offset +32
-mov $0x0,%eax // Move 0 to %eax
-jb 0x5555555557c5 <func4+44> // If %ecx < %edi -> jump to instruction at offset +44.
-add $0x8,%rsp // add 8 bytes to the stack pointer
-ret // return
-lea -0x1(%rcx),%edx // LEA of $rxc - 1 into $edx
-call 0x555555555799 <func4> // Call itself
-add %eax,%eax // Double the value in %eax
-jmp 0x5555555557b4 <func4+27> // jump to the instruction at offset +27
-lea 0x1(%rcx),%esi
-call 0x555555555799 <func4>
-lea 0x1(%rax,%rax,1),%eax // LEA of %rax * 2 + 1 into $eax
-jmp 0x5555555557b4 <func4+27>
+sub $0x8,%rsp // subtract 8 bytes from the stack pointer
+mov %edx,%ecx // Move the value in register %edx to %ecx
+sub %esi,%ecx // Subtract the value in %esi from %ecx
+shr %ecx // Right shift the value in %ecx by one bit (dividing the value by 2)
+add %esi,%ecx // Add the value in %esi to %ecx
+cmp %edi,%ecx // Compare
+ja 0x5555555557b9 <func4+32> // If %ecx > %edi -> jump to instruction at offset +32
+mov $0x0,%eax // Move 0 to %eax
+jb 0x5555555557c5 <func4+44> // If %ecx < %edi -> jump to instruction at offset +44.
+add $0x8,%rsp // add 8 bytes to the stack pointer
+ret // return
+lea -0x1(%rcx),%edx // LEA of $rxc - 1 into $edx
+call 0x555555555799 <func4> // Call itself
+add %eax,%eax // Double the value in %eax
+jmp 0x5555555557b4 <func4+27> // jump to the instruction at offset +27
+lea 0x1(%rcx),%esi
+call 0x555555555799 <func4>
+lea 0x1(%rax,%rax,1),%eax // LEA of %rax * 2 + 1 into $eax
+jmp 0x5555555557b4 <func4+27>
@@ -3875,79 +3884,80 @@ jmp 0x5555555557b4 <func4+27>
Okay, so we know that the number needed to be passed to func4
is 5. But, what about the second digit?
If we go back to the code for <phase_4>
, we can see that:
-
0x000055555555581f <+76>: cmpl $0x2,0x8(%rsp)
- 0x0000555555555824 <+81>: je 0x55555555582b <phase_4+88>
-
- If we go back to the code for <phase_4>
, we can see that:
0x000055555555581f <+76>: cmpl $0x2,0x8(%rsp)
+ 0x0000555555555824 <+81>: je 0x55555555582b <phase_4+88>
+
+The value at $rsp+8
should be equal to 2. So, let us try passing 5 2
as our input.
...
-Phase 1 defused. How about the next one?
-That's number 2. Keep going!
-Halfway there!
-5 2
+Phase 1 defused. How about the next one?
+That's number 2. Keep going!
+Halfway there!
+5 2
-Breakpoint 1, 0x00005555555557d3 in phase_4 ()
-(gdb) continue
+Breakpoint 1, 0x00005555555557d3 in phase_4 ()
+(gdb) continue
Continuing.
-So you got that one. Try this one.
+So you got that one. Try this one.
So you got that one. Try this one.
-test string
-
-Breakpoint 1, 0x0000555555555830 in phase_5 ()
-(gdb) disas phase_5
-Dump of assembler code for function phase_5:
-=> 0x0000555555555830 <+0>: endbr64
- 0x0000555555555834 <+4>: push %rbx
- 0x0000555555555835 <+5>: sub $0x10,%rsp
- 0x0000555555555839 <+9>: mov %rdi,%rbx
- 0x000055555555583c <+12>: call 0x555555555b10 <string_length>
- 0x0000555555555841 <+17>: cmp $0x6,%eax
- 0x0000555555555844 <+20>: jne 0x55555555588b <phase_5+91>
- 0x0000555555555846 <+22>: mov $0x0,%eax
- 0x000055555555584b <+27>: lea 0x199e(%rip),%rcx # 0x5555555571f0 <array.0>
- 0x0000555555555852 <+34>: movzbl (%rbx,%rax,1),%edx
- 0x0000555555555856 <+38>: and $0xf,%edx
- 0x0000555555555859 <+41>: movzbl (%rcx,%rdx,1),%edx
- 0x000055555555585d <+45>: mov %dl,0x9(%rsp,%rax,1)
- 0x0000555555555861 <+49>: add $0x1,%rax
- 0x0000555555555865 <+53>: cmp $0x6,%rax
- 0x0000555555555869 <+57>: jne 0x555555555852 <phase_5+34>
- 0x000055555555586b <+59>: movb $0x0,0xf(%rsp)
- 0x0000555555555870 <+64>: lea 0x9(%rsp),%rdi
- 0x0000555555555875 <+69>: lea 0x1943(%rip),%rsi # 0x5555555571bf
- 0x000055555555587c <+76>: call 0x555555555b31 <strings_not_equal>
- 0x0000555555555881 <+81>: test %eax,%eax
- 0x0000555555555883 <+83>: jne 0x555555555892 <phase_5+98>
- 0x0000555555555885 <+85>: add $0x10,%rsp
- 0x0000555555555889 <+89>: pop %rbx
- 0x000055555555588a <+90>: ret
- 0x000055555555588b <+91>: call 0x555555555d4a <explode_bomb>
- 0x0000555555555890 <+96>: jmp 0x555555555846 <phase_5+22>
- 0x0000555555555892 <+98>: call 0x555555555d4a <explode_bomb>
- 0x0000555555555897 <+103>: jmp 0x555555555885 <phase_5+85>
-End of assembler dump.
-(gdb)
+So you got that one. Try this one.
+test string
+
+Breakpoint 1, 0x0000555555555830 in phase_5 ()
+(gdb) disas phase_5
+Dump of assembler code for function phase_5:
+=> 0x0000555555555830 <+0>: endbr64
+ 0x0000555555555834 <+4>: push %rbx
+ 0x0000555555555835 <+5>: sub $0x10,%rsp
+ 0x0000555555555839 <+9>: mov %rdi,%rbx
+ 0x000055555555583c <+12>: call 0x555555555b10 <string_length>
+ 0x0000555555555841 <+17>: cmp $0x6,%eax
+ 0x0000555555555844 <+20>: jne 0x55555555588b <phase_5+91>
+ 0x0000555555555846 <+22>: mov $0x0,%eax
+ 0x000055555555584b <+27>: lea 0x199e(%rip),%rcx # 0x5555555571f0 <array.0>
+ 0x0000555555555852 <+34>: movzbl (%rbx,%rax,1),%edx
+ 0x0000555555555856 <+38>: and $0xf,%edx
+ 0x0000555555555859 <+41>: movzbl (%rcx,%rdx,1),%edx
+ 0x000055555555585d <+45>: mov %dl,0x9(%rsp,%rax,1)
+ 0x0000555555555861 <+49>: add $0x1,%rax
+ 0x0000555555555865 <+53>: cmp $0x6,%rax
+ 0x0000555555555869 <+57>: jne 0x555555555852 <phase_5+34>
+ 0x000055555555586b <+59>: movb $0x0,0xf(%rsp)
+ 0x0000555555555870 <+64>: lea 0x9(%rsp),%rdi
+ 0x0000555555555875 <+69>: lea 0x1943(%rip),%rsi # 0x5555555571bf
+ 0x000055555555587c <+76>: call 0x555555555b31 <strings_not_equal>
+ 0x0000555555555881 <+81>: test %eax,%eax
+ 0x0000555555555883 <+83>: jne 0x555555555892 <phase_5+98>
+ 0x0000555555555885 <+85>: add $0x10,%rsp
+ 0x0000555555555889 <+89>: pop %rbx
+ 0x000055555555588a <+90>: ret
+ 0x000055555555588b <+91>: call 0x555555555d4a <explode_bomb>
+ 0x0000555555555890 <+96>: jmp 0x555555555846 <phase_5+22>
+ 0x0000555555555892 <+98>: call 0x555555555d4a <explode_bomb>
+ 0x0000555555555897 <+103>: jmp 0x555555555885 <phase_5+85>
+End of assembler dump.
+(gdb)
...
- 0x000055555555583c <+12>: call 0x555555555b10 <string_length>
- 0x0000555555555841 <+17>: cmp $0x6,%eax
- 0x0000555555555844 <+20>: jne 0x55555555588b <phase_5+91>
+ 0x000055555555583c <+12>: call 0x555555555b10 <string_length>
+ 0x0000555555555841 <+17>: cmp $0x6,%eax
+ 0x0000555555555844 <+20>: jne 0x55555555588b <phase_5+91>
...
- 0x000055555555588b <+91>: call 0x555555555d4a <explode_bomb>
+ 0x000055555555588b <+91>: call 0x555555555d4a <explode_bomb>
...
We can check the reference string we need, which gdb
has marked as # 0x5555555571bf
, and the lookup table marked as # 0x5555555571f0 <array.0>
(gdb) x/s 0x5555555571bf
-0x5555555571bf: "bruins"
-(gdb) x/s 0x5555555571f0
-0x5555555571f0 <array.0>: "maduiersnfotvbylSo you think you can stop the bomb with ctrl-c, do you?"
-(gdb)
+(gdb) x/s 0x5555555571bf
+0x5555555571bf: "bruins"
+(gdb) x/s 0x5555555571f0
+0x5555555571f0 <array.0>: "maduiersnfotvbylSo you think you can stop the bomb with ctrl-c, do you?"
+(gdb)
...
-That's number 2. Keep going!
-Halfway there!
-So you got that one. Try this one.
+That's number 2. Keep going!
+Halfway there!
+So you got that one. Try this one.
mfcdhg
-Breakpoint 1, 0x0000555555555830 in phase_5 ()
-(gdb) continue
+Breakpoint 1, 0x0000555555555830 in phase_5 ()
+(gdb) continue
Continuing.
-Good work! On to the next...
+Good work! On to the next...
Good work! On to the next...
-test string
-
-Breakpoint 1, 0x0000555555555899 in phase_6 ()
-(gdb) disas phase_6
-Dump of assembler code for function phase_6:
-=> 0x0000555555555899 <+0>: endbr64
- 0x000055555555589d <+4>: push %r15
- 0x000055555555589f <+6>: push %r14
- 0x00005555555558a1 <+8>: push %r13
- 0x00005555555558a3 <+10>: push %r12
- 0x00005555555558a5 <+12>: push %rbp
- 0x00005555555558a6 <+13>: push %rbx
- 0x00005555555558a7 <+14>: sub $0x68,%rsp
- 0x00005555555558ab <+18>: lea 0x40(%rsp),%rax
- 0x00005555555558b0 <+23>: mov %rax,%r14
- 0x00005555555558b3 <+26>: mov %rax,0x8(%rsp)
- 0x00005555555558b8 <+31>: mov %rax,%rsi
- 0x00005555555558bb <+34>: call 0x555555555d97 <read_six_numbers>
- 0x00005555555558c0 <+39>: mov %r14,%r12
- 0x00005555555558c3 <+42>: mov $0x1,%r15d
- 0x00005555555558c9 <+48>: mov %r14,%r13
- 0x00005555555558cc <+51>: jmp 0x555555555997 <phase_6+254>
- 0x00005555555558d1 <+56>: call 0x555555555d4a <explode_bomb>
- 0x00005555555558d6 <+61>: jmp 0x5555555559a9 <phase_6+272>
- 0x00005555555558db <+66>: add $0x1,%rbx
- 0x00005555555558df <+70>: cmp $0x5,%ebx
- 0x00005555555558e2 <+73>: jg 0x55555555598f <phase_6+246>
- 0x00005555555558e8 <+79>: mov 0x0(%r13,%rbx,4),%eax
- 0x00005555555558ed <+84>: cmp %eax,0x0(%rbp)
- 0x00005555555558f0 <+87>: jne 0x5555555558db <phase_6+66>
- 0x00005555555558f2 <+89>: call 0x555555555d4a <explode_bomb>
- 0x00005555555558f7 <+94>: jmp 0x5555555558db <phase_6+66>
- 0x00005555555558f9 <+96>: mov 0x8(%rsp),%rdx
- 0x00005555555558fe <+101>: add $0x18,%rdx
- 0x0000555555555902 <+105>: mov $0x7,%ecx
- 0x0000555555555907 <+110>: mov %ecx,%eax
- 0x0000555555555909 <+112>: sub (%r12),%eax
- 0x000055555555590d <+116>: mov %eax,(%r12)
- 0x0000555555555911 <+120>: add $0x4,%r12
- 0x0000555555555915 <+124>: cmp %r12,%rdx
- 0x0000555555555918 <+127>: jne 0x555555555907 <phase_6+110>
- 0x000055555555591a <+129>: mov $0x0,%esi
- 0x000055555555591f <+134>: mov 0x40(%rsp,%rsi,4),%ecx
- 0x0000555555555923 <+138>: mov $0x1,%eax
- 0x0000555555555928 <+143>: lea 0x3d01(%rip),%rdx # 0x555555559630 <node1>
---Type <RET> for more, q to quit, c to continue without paging--
- 0x000055555555592f <+150>: cmp $0x1,%ecx
- 0x0000555555555932 <+153>: jle 0x55555555593f <phase_6+166>
- 0x0000555555555934 <+155>: mov 0x8(%rdx),%rdx
- 0x0000555555555938 <+159>: add $0x1,%eax
- 0x000055555555593b <+162>: cmp %ecx,%eax
- 0x000055555555593d <+164>: jne 0x555555555934 <phase_6+155>
- 0x000055555555593f <+166>: mov %rdx,0x10(%rsp,%rsi,8)
- 0x0000555555555944 <+171>: add $0x1,%rsi
- 0x0000555555555948 <+175>: cmp $0x6,%rsi
- 0x000055555555594c <+179>: jne 0x55555555591f <phase_6+134>
- 0x000055555555594e <+181>: mov 0x10(%rsp),%rbx
- 0x0000555555555953 <+186>: mov 0x18(%rsp),%rax
- 0x0000555555555958 <+191>: mov %rax,0x8(%rbx)
- 0x000055555555595c <+195>: mov 0x20(%rsp),%rdx
- 0x0000555555555961 <+200>: mov %rdx,0x8(%rax)
- 0x0000555555555965 <+204>: mov 0x28(%rsp),%rax
- 0x000055555555596a <+209>: mov %rax,0x8(%rdx)
- 0x000055555555596e <+213>: mov 0x30(%rsp),%rdx
- 0x0000555555555973 <+218>: mov %rdx,0x8(%rax)
- 0x0000555555555977 <+222>: mov 0x38(%rsp),%rax
- 0x000055555555597c <+227>: mov %rax,0x8(%rdx)
- 0x0000555555555980 <+231>: movq $0x0,0x8(%rax)
- 0x0000555555555988 <+239>: mov $0x5,%ebp
- 0x000055555555598d <+244>: jmp 0x5555555559c4 <phase_6+299>
- 0x000055555555598f <+246>: add $0x1,%r15
- 0x0000555555555993 <+250>: add $0x4,%r14
- 0x0000555555555997 <+254>: mov %r14,%rbp
- 0x000055555555599a <+257>: mov (%r14),%eax
- 0x000055555555599d <+260>: sub $0x1,%eax
- 0x00005555555559a0 <+263>: cmp $0x5,%eax
- 0x00005555555559a3 <+266>: ja 0x5555555558d1 <phase_6+56>
- 0x00005555555559a9 <+272>: cmp $0x5,%r15d
- 0x00005555555559ad <+276>: jg 0x5555555558f9 <phase_6+96>
- 0x00005555555559b3 <+282>: mov %r15,%rbx
- 0x00005555555559b6 <+285>: jmp 0x5555555558e8 <phase_6+79>
- 0x00005555555559bb <+290>: mov 0x8(%rbx),%rbx
- 0x00005555555559bf <+294>: sub $0x1,%ebp
- 0x00005555555559c2 <+297>: je 0x5555555559d5 <phase_6+316>
- 0x00005555555559c4 <+299>: mov 0x8(%rbx),%rax
- 0x00005555555559c8 <+303>: mov (%rax),%eax
- 0x00005555555559ca <+305>: cmp %eax,(%rbx)
---Type <RET> for more, q to quit, c to continue without paging--
- 0x00005555555559cc <+307>: jge 0x5555555559bb <phase_6+290>
- 0x00005555555559ce <+309>: call 0x555555555d4a <explode_bomb>
- 0x00005555555559d3 <+314>: jmp 0x5555555559bb <phase_6+290>
- 0x00005555555559d5 <+316>: add $0x68,%rsp
- 0x00005555555559d9 <+320>: pop %rbx
- 0x00005555555559da <+321>: pop %rbp
- 0x00005555555559db <+322>: pop %r12
- 0x00005555555559dd <+324>: pop %r13
- 0x00005555555559df <+326>: pop %r14
- 0x00005555555559e1 <+328>: pop %r15
- 0x00005555555559e3 <+330>: ret
-End of assembler dump.
-(gdb)
+Good work! On to the next...
+test string
+
+Breakpoint 1, 0x0000555555555899 in phase_6 ()
+(gdb) disas phase_6
+Dump of assembler code for function phase_6:
+=> 0x0000555555555899 <+0>: endbr64
+ 0x000055555555589d <+4>: push %r15
+ 0x000055555555589f <+6>: push %r14
+ 0x00005555555558a1 <+8>: push %r13
+ 0x00005555555558a3 <+10>: push %r12
+ 0x00005555555558a5 <+12>: push %rbp
+ 0x00005555555558a6 <+13>: push %rbx
+ 0x00005555555558a7 <+14>: sub $0x68,%rsp
+ 0x00005555555558ab <+18>: lea 0x40(%rsp),%rax
+ 0x00005555555558b0 <+23>: mov %rax,%r14
+ 0x00005555555558b3 <+26>: mov %rax,0x8(%rsp)
+ 0x00005555555558b8 <+31>: mov %rax,%rsi
+ 0x00005555555558bb <+34>: call 0x555555555d97 <read_six_numbers>
+ 0x00005555555558c0 <+39>: mov %r14,%r12
+ 0x00005555555558c3 <+42>: mov $0x1,%r15d
+ 0x00005555555558c9 <+48>: mov %r14,%r13
+ 0x00005555555558cc <+51>: jmp 0x555555555997 <phase_6+254>
+ 0x00005555555558d1 <+56>: call 0x555555555d4a <explode_bomb>
+ 0x00005555555558d6 <+61>: jmp 0x5555555559a9 <phase_6+272>
+ 0x00005555555558db <+66>: add $0x1,%rbx
+ 0x00005555555558df <+70>: cmp $0x5,%ebx
+ 0x00005555555558e2 <+73>: jg 0x55555555598f <phase_6+246>
+ 0x00005555555558e8 <+79>: mov 0x0(%r13,%rbx,4),%eax
+ 0x00005555555558ed <+84>: cmp %eax,0x0(%rbp)
+ 0x00005555555558f0 <+87>: jne 0x5555555558db <phase_6+66>
+ 0x00005555555558f2 <+89>: call 0x555555555d4a <explode_bomb>
+ 0x00005555555558f7 <+94>: jmp 0x5555555558db <phase_6+66>
+ 0x00005555555558f9 <+96>: mov 0x8(%rsp),%rdx
+ 0x00005555555558fe <+101>: add $0x18,%rdx
+ 0x0000555555555902 <+105>: mov $0x7,%ecx
+ 0x0000555555555907 <+110>: mov %ecx,%eax
+ 0x0000555555555909 <+112>: sub (%r12),%eax
+ 0x000055555555590d <+116>: mov %eax,(%r12)
+ 0x0000555555555911 <+120>: add $0x4,%r12
+ 0x0000555555555915 <+124>: cmp %r12,%rdx
+ 0x0000555555555918 <+127>: jne 0x555555555907 <phase_6+110>
+ 0x000055555555591a <+129>: mov $0x0,%esi
+ 0x000055555555591f <+134>: mov 0x40(%rsp,%rsi,4),%ecx
+ 0x0000555555555923 <+138>: mov $0x1,%eax
+ 0x0000555555555928 <+143>: lea 0x3d01(%rip),%rdx # 0x555555559630 <node1>
+--Type <RET> for more, q to quit, c to continue without paging--
+ 0x000055555555592f <+150>: cmp $0x1,%ecx
+ 0x0000555555555932 <+153>: jle 0x55555555593f <phase_6+166>
+ 0x0000555555555934 <+155>: mov 0x8(%rdx),%rdx
+ 0x0000555555555938 <+159>: add $0x1,%eax
+ 0x000055555555593b <+162>: cmp %ecx,%eax
+ 0x000055555555593d <+164>: jne 0x555555555934 <phase_6+155>
+ 0x000055555555593f <+166>: mov %rdx,0x10(%rsp,%rsi,8)
+ 0x0000555555555944 <+171>: add $0x1,%rsi
+ 0x0000555555555948 <+175>: cmp $0x6,%rsi
+ 0x000055555555594c <+179>: jne 0x55555555591f <phase_6+134>
+ 0x000055555555594e <+181>: mov 0x10(%rsp),%rbx
+ 0x0000555555555953 <+186>: mov 0x18(%rsp),%rax
+ 0x0000555555555958 <+191>: mov %rax,0x8(%rbx)
+ 0x000055555555595c <+195>: mov 0x20(%rsp),%rdx
+ 0x0000555555555961 <+200>: mov %rdx,0x8(%rax)
+ 0x0000555555555965 <+204>: mov 0x28(%rsp),%rax
+ 0x000055555555596a <+209>: mov %rax,0x8(%rdx)
+ 0x000055555555596e <+213>: mov 0x30(%rsp),%rdx
+ 0x0000555555555973 <+218>: mov %rdx,0x8(%rax)
+ 0x0000555555555977 <+222>: mov 0x38(%rsp),%rax
+ 0x000055555555597c <+227>: mov %rax,0x8(%rdx)
+ 0x0000555555555980 <+231>: movq $0x0,0x8(%rax)
+ 0x0000555555555988 <+239>: mov $0x5,%ebp
+ 0x000055555555598d <+244>: jmp 0x5555555559c4 <phase_6+299>
+ 0x000055555555598f <+246>: add $0x1,%r15
+ 0x0000555555555993 <+250>: add $0x4,%r14
+ 0x0000555555555997 <+254>: mov %r14,%rbp
+ 0x000055555555599a <+257>: mov (%r14),%eax
+ 0x000055555555599d <+260>: sub $0x1,%eax
+ 0x00005555555559a0 <+263>: cmp $0x5,%eax
+ 0x00005555555559a3 <+266>: ja 0x5555555558d1 <phase_6+56>
+ 0x00005555555559a9 <+272>: cmp $0x5,%r15d
+ 0x00005555555559ad <+276>: jg 0x5555555558f9 <phase_6+96>
+ 0x00005555555559b3 <+282>: mov %r15,%rbx
+ 0x00005555555559b6 <+285>: jmp 0x5555555558e8 <phase_6+79>
+ 0x00005555555559bb <+290>: mov 0x8(%rbx),%rbx
+ 0x00005555555559bf <+294>: sub $0x1,%ebp
+ 0x00005555555559c2 <+297>: je 0x5555555559d5 <phase_6+316>
+ 0x00005555555559c4 <+299>: mov 0x8(%rbx),%rax
+ 0x00005555555559c8 <+303>: mov (%rax),%eax
+ 0x00005555555559ca <+305>: cmp %eax,(%rbx)
+--Type <RET> for more, q to quit, c to continue without paging--
+ 0x00005555555559cc <+307>: jge 0x5555555559bb <phase_6+290>
+ 0x00005555555559ce <+309>: call 0x555555555d4a <explode_bomb>
+ 0x00005555555559d3 <+314>: jmp 0x5555555559bb <phase_6+290>
+ 0x00005555555559d5 <+316>: add $0x68,%rsp
+ 0x00005555555559d9 <+320>: pop %rbx
+ 0x00005555555559da <+321>: pop %rbp
+ 0x00005555555559db <+322>: pop %r12
+ 0x00005555555559dd <+324>: pop %r13
+ 0x00005555555559df <+326>: pop %r14
+ 0x00005555555559e1 <+328>: pop %r15
+ 0x00005555555559e3 <+330>: ret
+End of assembler dump.
+(gdb)
Again, we see the familiar read_six_digits
function.
Let us analyse this function in chunks: -
0x00005555555558bb <+34>: call 0x555555555d97 <readsixnumbers>
- 0x00005555555558c0 <+39>: mov %r14,%r12
- 0x00005555555558c3 <+42>: mov $0x1,%r15d
- 0x00005555555558c9 <+48>: mov %r14,%r13
- 0x00005555555558cc <+51>: jmp 0x555555555997 <phase_6+254>
-
- Let us analyse this function in chunks:
+ + 0x00005555555558bb <+34>: call 0x555555555d97 <read_six_numbers>
+ 0x00005555555558c0 <+39>: mov %r14,%r12
+ 0x00005555555558c3 <+42>: mov $0x1,%r15d
+ 0x00005555555558c9 <+48>: mov %r14,%r13
+ 0x00005555555558cc <+51>: jmp 0x555555555997 <phase_6+254>
+
+mov %r14,%r12
: %r14
should be pointing to the location of the stack where the numbers were read into. This address is copied onto %r12
2.2. mov $0x1,%r15d
: The value 1
is moved into %r15
register (probably acting like a counter)
2.3. mov %r14,%r13
: The value is also copied to %r13
-Jump to start of loop:
+0x0000555555555997 <+254>: mov %r14,%rbp
-0x000055555555599a <+257>: mov (%r14),%eax
-0x000055555555599d <+260>: sub $0x1,%eax
-0x00005555555559a0 <+263>: cmp $0x5,%eax
-0x00005555555559a3 <+266>: ja 0x5555555558d1 <phase_6+56>
+ 0x0000555555555997 <+254>: mov %r14,%rbp
+ 0x000055555555599a <+257>: mov (%r14),%eax
+ 0x000055555555599d <+260>: sub $0x1,%eax
+ 0x00005555555559a0 <+263>: cmp $0x5,%eax
+ 0x00005555555559a3 <+266>: ja 0x5555555558d1 <phase_6+56>
-
Initialise register and point to first number in sequence
mov (%r14),%eax
-> load the current number in the sequence
2.2. sub $0x1,%eax
-> decrement number by 1ja 0x5555555558d1 <phase_6+56>
: jump if given value is > 5 or < 0
=> All numbers should be between 1 and 6. -
0x00005555555559a9 <+272>: cmp $0x5,%r15d
- 0x00005555555559ad <+276>: jg 0x5555555558f9 <phase_6+96>
-
- This checks if the value stored in %r15
is > 5, if it is then it jumps somewhere else. This validates our assumption that %r15
is acting as a counter.
-
0x00005555555559b3 <+282>: mov %r15,%rbx
- 0x00005555555559b6 <+285>: jmp 0x5555555558e8 <phase_6+79>
-
- Let us jump to +79 -
0x00005555555558e8 <+79>: mov 0x0(%r13,%rbx,4),%eax
- 0x00005555555558ed <+84>: cmp %eax,0x0(%rbp)
- 0x00005555555558f0 <+87>: jne 0x5555555558db <phase6+66>
- 0x00005555555558f2 <+89>: call 0x555555555d4a <explodebomb>
- 0x00005555555558f7 <+94>: jmp 0x5555555558db <phase_6+66>
-
- This section deals with checking if all the numbers in the sequence are unique or not. Thus, we need to ensure out 6 digits are unique -
0x00005555555558db <+66>: add $0x1,%rbx // Increments by 1
- 0x00005555555558df <+70>: cmp $0x5,%ebx
- 0x00005555555558e2 <+73>: jg 0x55555555598f <phase6+246> // Jump if > 5 (Loop iterations are complete)
- 0x00005555555558e8 <+79>: mov 0x0(%r13,%rbx,4),%eax
- 0x00005555555558ed <+84>: cmp %eax,0x0(%rbp)
- 0x00005555555558f0 <+87>: jne 0x5555555558db <phase6+66> // Again, check if the number being seen is unique
-
- => All numbers should be between 1 and 6.
+ + 0x00005555555559a9 <+272>: cmp $0x5,%r15d
+ 0x00005555555559ad <+276>: jg 0x5555555558f9 <phase_6+96>
+
+This checks if the value stored in %r15
is > 5, if it is then it jumps somewhere else. This validates our assumption that %r15
is acting as a counter.
0x00005555555559b3 <+282>: mov %r15,%rbx
+ 0x00005555555559b6 <+285>: jmp 0x5555555558e8 <phase_6+79>
+
+Let us jump to +79
+ + 0x00005555555558e8 <+79>: mov 0x0(%r13,%rbx,4),%eax
+ 0x00005555555558ed <+84>: cmp %eax,0x0(%rbp)
+ 0x00005555555558f0 <+87>: jne 0x5555555558db <phase_6+66>
+ 0x00005555555558f2 <+89>: call 0x555555555d4a <explode_bomb>
+ 0x00005555555558f7 <+94>: jmp 0x5555555558db <phase_6+66>
+
+This section deals with checking if all the numbers in the sequence are unique or not. Thus, we need to ensure out 6 digits are unique
+ + 0x00005555555558db <+66>: add $0x1,%rbx // Increments by 1
+ 0x00005555555558df <+70>: cmp $0x5,%ebx
+ 0x00005555555558e2 <+73>: jg 0x55555555598f <phase_6+246> // Jump if > 5 (Loop iterations are complete)
+ 0x00005555555558e8 <+79>: mov 0x0(%r13,%rbx,4),%eax
+ 0x00005555555558ed <+84>: cmp %eax,0x0(%rbp)
+ 0x00005555555558f0 <+87>: jne 0x5555555558db <phase_6+66> // Again, check if the number being seen is unique
+
+Now we know that the numbers are unique, between 1-6 (inclusive).
@@ -4218,36 +4236,36 @@ End of assembler dump.Let us try to figure out what 0x0000555555555928 <+143>: lea 0x3d01(%rip),%rdx # 0x555555559630 <node1>
is:
(gdb) x/30wx 0x555555559630
-0x555555559630 <node1>: 0x000000d9 0x00000001 0x55559640 0x00005555
-0x555555559640 <node2>: 0x000003ab 0x00000002 0x55559650 0x00005555
-0x555555559650 <node3>: 0x0000014f 0x00000003 0x55559660 0x00005555
-0x555555559660 <node4>: 0x000000a1 0x00000004 0x55559670 0x00005555
-0x555555559670 <node5>: 0x000001b3 0x00000005 0x55559120 0x00005555
-0x555555559680 <host_table>: 0x555573f5 0x00005555 0x5555740f 0x00005555
-0x555555559690 <host_table+16>: 0x55557429 0x00005555 0x00000000 0x00000000
-0x5555555596a0 <host_table+32>: 0x00000000 0x00000000
-(gdb) x/30wx 0x555555559120
-0x555555559120 <node6>: 0x000002da 0x00000006 0x00000000 0x00000000
-0x555555559130: 0x00000000 0x00000000 0x00000000 0x00000000
-0x555555559140 <userid>: 0x61767861 0x38383535 0x00000000 0x00000000
-0x555555559150 <userid+16>: 0x00000000 0x00000000 0x00000000 0x00000000
-0x555555559160 <userid+32>: 0x00000000 0x00000000 0x00000000 0x00000000
-0x555555559170 <userid+48>: 0x00000000 0x00000000 0x00000000 0x00000000
-0x555555559180 <userid+64>: 0x00000000 0x00000000 0x00000000 0x00000000
-0x555555559190 <userid+80>: 0x00000000 0x00000000
-(gdb)
+(gdb) x/30wx 0x555555559630
+0x555555559630 <node1>: 0x000000d9 0x00000001 0x55559640 0x00005555
+0x555555559640 <node2>: 0x000003ab 0x00000002 0x55559650 0x00005555
+0x555555559650 <node3>: 0x0000014f 0x00000003 0x55559660 0x00005555
+0x555555559660 <node4>: 0x000000a1 0x00000004 0x55559670 0x00005555
+0x555555559670 <node5>: 0x000001b3 0x00000005 0x55559120 0x00005555
+0x555555559680 <host_table>: 0x555573f5 0x00005555 0x5555740f 0x00005555
+0x555555559690 <host_table+16>: 0x55557429 0x00005555 0x00000000 0x00000000
+0x5555555596a0 <host_table+32>: 0x00000000 0x00000000
+(gdb) x/30wx 0x555555559120
+0x555555559120 <node6>: 0x000002da 0x00000006 0x00000000 0x00000000
+0x555555559130: 0x00000000 0x00000000 0x00000000 0x00000000
+0x555555559140 <userid>: 0x61767861 0x38383535 0x00000000 0x00000000
+0x555555559150 <userid+16>: 0x00000000 0x00000000 0x00000000 0x00000000
+0x555555559160 <userid+32>: 0x00000000 0x00000000 0x00000000 0x00000000
+0x555555559170 <userid+48>: 0x00000000 0x00000000 0x00000000 0x00000000
+0x555555559180 <userid+64>: 0x00000000 0x00000000 0x00000000 0x00000000
+0x555555559190 <userid+80>: 0x00000000 0x00000000
+(gdb)
It appears that this is a linked list. With roughly the following structure:
struct node {
- int value;
- int index;
- struct node *next;
-};
+struct node {
+ int value;
+ int index;
+ struct node *next;
+};
sudo apt update && sudo apt install certbot -y
+sudo apt update && sudo apt install certbot -y
sudo certbot certonly --manual --preferred-challenges dns-01 --email senpai@email.com -d mydomain.duckdns.org
+sudo certbot certonly --manual --preferred-challenges dns-01 --email senpai@email.com -d mydomain.duckdns.org
You can check if the TXT records have been updated by using the dig
command:
dig navanspi.duckdns.org TXT
-; <<>> DiG 9.16.1-Ubuntu <<>> navanspi.duckdns.org TXT
-;; global options: +cmd
-;; Got answer:
-;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27592
-;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
+dig navanspi.duckdns.org TXT
+; <<>> DiG 9.16.1-Ubuntu <<>> navanspi.duckdns.org TXT
+;; global options: +cmd
+;; Got answer:
+;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27592
+;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
-;; OPT PSEUDOSECTION:
-; EDNS: version: 0, flags:; udp: 65494
-;; QUESTION SECTION:
-;navanspi.duckdns.org. IN TXT
+;; OPT PSEUDOSECTION:
+; EDNS: version: 0, flags:; udp: 65494
+;; QUESTION SECTION:
+;navanspi.duckdns.org. IN TXT
-;; ANSWER SECTION:
-navanspi.duckdns.org. 60 IN TXT "4OKbijIJmc82Yv2NiGVm1RmaBHSCZ_230qNtj9YA-qk"
+;; ANSWER SECTION:
+navanspi.duckdns.org. 60 IN TXT "4OKbijIJmc82Yv2NiGVm1RmaBHSCZ_230qNtj9YA-qk"
-;; Query time: 275 msec
-;; SERVER: 127.0.0.53#53(127.0.0.53)
-;; WHEN: Tue Nov 17 15:23:15 IST 2020
-;; MSG SIZE rcvd: 105
+;; Query time: 275 msec
+;; SERVER: 127.0.0.53#53(127.0.0.53)
+;; WHEN: Tue Nov 17 15:23:15 IST 2020
+;; MSG SIZE rcvd: 105
gunicorn api:app -k uvicorn.workers.UvicornWorker -b 0.0.0.0:7589
+gunicorn api:app -k uvicorn.workers.UvicornWorker -b 0.0.0.0:7589
To use the certificate with it, simply copy the cert.pem
and privkey.pem
to your working directory ( change the appropriate permissions ) and include them in the command
-gunicorn api:app -k uvicorn.workers.UvicornWorker -b 0.0.0.0:7589 --certfile=cert.pem --keyfile=privkey.pem
+gunicorn api:app -k uvicorn.workers.UvicornWorker -b 0.0.0.0:7589 --certfile=cert.pem --keyfile=privkey.pem
@@ -4431,7 +4449,7 @@ a CUDA compatible MXNet package.
Downloading the Dataset
-!wget -q "https://github.com/joolsa/fake_real_news_dataset/raw/master/fake_or_real_news.csv.zip"
+!wget -q "https://github.com/joolsa/fake_real_news_dataset/raw/master/fake_or_real_news.csv.zip"
!unzip fake_or_real_news.csv.zip
@@ -4704,176 +4722,176 @@ DescriptionThe bag-of-words model is a simplifying representation used in NLP, i
</main>
<script src="https://gitcdn.xyz/repo/rbren/rss-parser/master/dist/rss-parser.js"></script>
-<script>
-
-const feeds = {
- "BuzzFeed - India": {
- "link":"https://www.buzzfeed.com/in.xml",
- "summary":true
- },
- "New Yorker": {
- "link":"http://www.newyorker.com/feed/news",
- },
- "Vox":{
- "link":"https://www.vox.com/rss/index.xml",
- "limit": 3
- },
- "r/Jokes":{
- "link":"https://reddit.com/r/Jokes/hot/.rss?sort=hot",
- "ignore": ["repost","discord"]
- }
-}
-
-const config_extra = {
-"Responsive-Images": true,
-"direct-link": false,
-"show-date":false,
-"left-column":false,
-"defaults": {
- "limit": 5,
- "summary": true
-}
-}
-
-const CORS_PROXY = "https://cors-anywhere.herokuapp.com/"
-
-var contents_title = document.createElement("h2")
-contents_title.textContent = "Contents"
-contents_title.classList.add("pb-1")
-document.getElementById("contents").appendChild(contents_title)
-
-async function myfunc(key){
-
- var count_lim = feeds[key]["limit"]
- var count_lim = (count_lim === undefined) ? config_extra["defaults"]["limit"] : count_lim
-
- var show_summary = feeds[key]["summary"]
- var show_summary = (show_summary === undefined) ? config_extra["defaults"]["summary"] : show_summary
-
- var ignore_tags = feeds[key]["ignore"]
- var ignore_tags = (ignore_tags === undefined) ? [] : ignore_tags
-
- var contents = document.createElement("a")
- contents.href = "#" + key
- contents.classList.add("list-group-item","list-group-item-action")
- contents.textContent = key
- document.getElementById("contents").appendChild(contents)
- var feed_div = document.createElement("div")
- feed_div.id = key
- feed_div.setAttribute("id", key);
- var title = document.createElement("h2");
- title.textContent = "From " + key;
- title.classList.add("pb-1")
- feed_div.appendChild(title)
- document.getElementById("feed").appendChild(feed_div)
- var parser = new RSSParser();
- var countPosts = 0
- parser.parseURL(CORS_PROXY + feeds[key]["link"], function(err, feed) {
- if (err) throw err;
- feed.items.forEach(function(entry) {
- if (countPosts < count_lim) {
-
- var skip = false
- for(var i = 0; i < ignore_tags.length; i++) {
- if (entry.title.includes(ignore_tags[i])){
- var skip = true
- } else if (entry.content.includes(ignore_tags[i])){
- var skip = true
- }
- }
-
- if (!skip) {
-
- var node = document.createElement("div");
- node.classList.add("card","mb-3");
- var row = document.createElement("div")
- row.classList.add("row","no-gutters")
-
- if (config_extra["left-column"]){
- var left_col = document.createElement("div")
- left_col.classList.add("col-md-2")
- var left_col_body = document.createElement("div")
- left_col_body.classList.add("card-body")
- }
-
- var right_col = document.createElement("div")
- if (config_extra["left-column"]){
- right_col.classList.add("col-md-10")
- }
- var node_title = document.createElement("h5")
-
- node_title.classList.add("card-header")
- node_title.innerHTML = entry.title
-
- node_body = document.createElement("div")
- node_body.classList.add("card-body")
-
- node_content = document.createElement("p")
-
- if (show_summary){
- node_content.innerHTML = entry.content
- }
- node_content.classList.add("card-text")
-
- if (config_extra["direct-link"]){
- node_link = document.createElement("p")
- node_link.classList.add("card-text")
- node_link.innerHTML = "<b>Link:</b> <a href='" + entry.link +"'>Direct Link</a>"
- if (config_extra["left-column"]){
- left_col_body.appendChild(node_link)
- } else {
- node_content.appendChild(node_link)
- }
- }
-
- if (config_extra["show-date"]){
- node_date = document.createElement("p")
- node_date.classList.add("card-text")
- node_date.innerHTML = "<p><b>Date: </b>" + entry.pubDate + "</p>"
- if (config_extra["left-column"]){
- left_col_body.appendChild(node_date)
- } else {
- node_content.appendChild(node_date)
-
- }
- }
-
- node.appendChild(node_title)
-
- node_body.appendChild(node_content)
-
- right_col.appendChild(node_body)
-
- if (config_extra["left-column"]){
- left_col.appendChild(left_col_body)
- row.appendChild(left_col)
- }
-
- row.appendChild(right_col)
-
- node.appendChild(row)
-
- document.getElementById(key).appendChild(node)
- countPosts+=1
- }
- }
- })
-
- if (config_extra["Responsive-Images"]){
- var inputs = document.getElementsByTagName('img')
- for(var i = 0; i < inputs.length; i++) {
- inputs[i].classList.add("img-fluid")
- }
- }
-
- })
-
- return true
-}
-(async () => {
-for(var key in feeds) {
- let result = await myfunc(key);
-}})();
+<script>
+
+const feeds = {
+ "BuzzFeed - India": {
+ "link":"https://www.buzzfeed.com/in.xml",
+ "summary":true
+ },
+ "New Yorker": {
+ "link":"http://www.newyorker.com/feed/news",
+ },
+ "Vox":{
+ "link":"https://www.vox.com/rss/index.xml",
+ "limit": 3
+ },
+ "r/Jokes":{
+ "link":"https://reddit.com/r/Jokes/hot/.rss?sort=hot",
+ "ignore": ["repost","discord"]
+ }
+}
+
+const config_extra = {
+"Responsive-Images": true,
+"direct-link": false,
+"show-date":false,
+"left-column":false,
+"defaults": {
+ "limit": 5,
+ "summary": true
+}
+}
+
+const CORS_PROXY = "https://cors-anywhere.herokuapp.com/"
+
+var contents_title = document.createElement("h2")
+contents_title.textContent = "Contents"
+contents_title.classList.add("pb-1")
+document.getElementById("contents").appendChild(contents_title)
+
+async function myfunc(key){
+
+ var count_lim = feeds[key]["limit"]
+ var count_lim = (count_lim === undefined) ? config_extra["defaults"]["limit"] : count_lim
+
+ var show_summary = feeds[key]["summary"]
+ var show_summary = (show_summary === undefined) ? config_extra["defaults"]["summary"] : show_summary
+
+ var ignore_tags = feeds[key]["ignore"]
+ var ignore_tags = (ignore_tags === undefined) ? [] : ignore_tags
+
+ var contents = document.createElement("a")
+ contents.href = "#" + key
+ contents.classList.add("list-group-item","list-group-item-action")
+ contents.textContent = key
+ document.getElementById("contents").appendChild(contents)
+ var feed_div = document.createElement("div")
+ feed_div.id = key
+ feed_div.setAttribute("id", key);
+ var title = document.createElement("h2");
+ title.textContent = "From " + key;
+ title.classList.add("pb-1")
+ feed_div.appendChild(title)
+ document.getElementById("feed").appendChild(feed_div)
+ var parser = new RSSParser();
+ var countPosts = 0
+ parser.parseURL(CORS_PROXY + feeds[key]["link"], function(err, feed) {
+ if (err) throw err;
+ feed.items.forEach(function(entry) {
+ if (countPosts < count_lim) {
+
+ var skip = false
+ for(var i = 0; i < ignore_tags.length; i++) {
+ if (entry.title.includes(ignore_tags[i])){
+ var skip = true
+ } else if (entry.content.includes(ignore_tags[i])){
+ var skip = true
+ }
+ }
+
+ if (!skip) {
+
+ var node = document.createElement("div");
+ node.classList.add("card","mb-3");
+ var row = document.createElement("div")
+ row.classList.add("row","no-gutters")
+
+ if (config_extra["left-column"]){
+ var left_col = document.createElement("div")
+ left_col.classList.add("col-md-2")
+ var left_col_body = document.createElement("div")
+ left_col_body.classList.add("card-body")
+ }
+
+ var right_col = document.createElement("div")
+ if (config_extra["left-column"]){
+ right_col.classList.add("col-md-10")
+ }
+ var node_title = document.createElement("h5")
+
+ node_title.classList.add("card-header")
+ node_title.innerHTML = entry.title
+
+ node_body = document.createElement("div")
+ node_body.classList.add("card-body")
+
+ node_content = document.createElement("p")
+
+ if (show_summary){
+ node_content.innerHTML = entry.content
+ }
+ node_content.classList.add("card-text")
+
+ if (config_extra["direct-link"]){
+ node_link = document.createElement("p")
+ node_link.classList.add("card-text")
+ node_link.innerHTML = "<b>Link:</b> <a href='" + entry.link +"'>Direct Link</a>"
+ if (config_extra["left-column"]){
+ left_col_body.appendChild(node_link)
+ } else {
+ node_content.appendChild(node_link)
+ }
+ }
+
+ if (config_extra["show-date"]){
+ node_date = document.createElement("p")
+ node_date.classList.add("card-text")
+ node_date.innerHTML = "<p><b>Date: </b>" + entry.pubDate + "</p>"
+ if (config_extra["left-column"]){
+ left_col_body.appendChild(node_date)
+ } else {
+ node_content.appendChild(node_date)
+
+ }
+ }
+
+ node.appendChild(node_title)
+
+ node_body.appendChild(node_content)
+
+ right_col.appendChild(node_body)
+
+ if (config_extra["left-column"]){
+ left_col.appendChild(left_col_body)
+ row.appendChild(left_col)
+ }
+
+ row.appendChild(right_col)
+
+ node.appendChild(row)
+
+ document.getElementById(key).appendChild(node)
+ countPosts+=1
+ }
+ }
+ })
+
+ if (config_extra["Responsive-Images"]){
+ var inputs = document.getElementsByTagName('img')
+ for(var i = 0; i < inputs.length; i++) {
+ inputs[i].classList.add("img-fluid")
+ }
+ }
+
+ })
+
+ return true
+}
+(async () => {
+for(var key in feeds) {
+ let result = await myfunc(key);
+}})();
</script>
<noscript>Uh Oh! Your browser does not support JavaScript or JavaScript is currently disabled. Please enable JavaScript or switch to a different browser.</noscript>
@@ -5262,46 +5280,46 @@ Seeing that you are reading this on Mastodon, and that I have updated this secti
/*
* Earth - Sun Orbit Plot
* Taken from Numerics tutorial
- */
-
-const G = 6.67e-11;
-const Msun = 2e30;
-const AU = 1.5e11;
-const v0 = Math.sqrt(G * Msun / AU); // SI
-
-function dR(r, v) {
- const dv = [-G * Msun / Math.pow(r[0] ** 2 + r[1] ** 2, 3 / 2) * r[0], -G * Msun / Math.pow(r[0] ** 2 + r[1] ** 2, 3 / 2) * r[1]];
- const dr = [...v];
- return [dr, dv];
-}
-
-// initialize system
-let r = [-AU, 0];
-const theta = Math.atan2(r[1], r[0]);
-let v = [-v0 * Math.sin(theta), v0 * Math.cos(theta)];
-
-const t = Array.from({ length: 1001 }, (_, i) => i / 100 + 0.0); // years
-const yearSec = 365 * 24 * 3600;
-const dt = (t[1] - t[0]) * yearSec; // s
-const x4Plot = Array.from({ length: t.length }, () => 0);
-const y4Plot = Array.from({ length: t.length }, () => 0);
-
-// integrate using RK4!
-for (let i = 0; i < t.length; i++) {
- const k1 = dR(r, v).map(x => x.map(y => y * dt));
- const k2 = dR(r.map((ri, j) => ri + k1[0][j] / 2), v.map((vi, j) => vi + k1[1][j] / 2)).map(x => x.map(y => y * dt));
- const k3 = dR(r.map((ri, j) => ri + k2[0][j] / 2), v.map((vi, j) => vi + k2[1][j] / 2)).map(x => x.map(y => y * dt));
- const k4 = dR(r.map((ri, j) => ri + k3[0][j]), v.map((vi, j) => vi + k3[1][j])).map(x => x.map(y => y * dt));
- r = r.map((ri, j) => ri + (k1[0][j] + 2 * k2[0][j] + 2 * k3[0][j] + k4[0][j]) / 6);
- v = v.map((vi, j) => vi + (k1[1][j] + 2 * k2[1][j] + 2 * k3[1][j] + k4[1][j]) / 6);
- x4Plot[i] = r[0];
- y4Plot[i] = r[1];
-}
-
-// make data for plot
-var sun = { x: 0, y: 0 };
-const earth = { x: x4Plot.map(x => x / AU), y: y4Plot.map(y => y / AU) };
-const circle = { x: Array.from({ length: 1001 }, (_, i) => Math.cos(i / 100 * 2 * Math.PI)), y: Array.from({ length: 1001 }, (_, i) => Math.sin(i / 100 * 2 * Math.PI)) };
+ */
+
+const G = 6.67e-11;
+const Msun = 2e30;
+const AU = 1.5e11;
+const v0 = Math.sqrt(G * Msun / AU); // SI
+
+function dR(r, v) {
+ const dv = [-G * Msun / Math.pow(r[0] ** 2 + r[1] ** 2, 3 / 2) * r[0], -G * Msun / Math.pow(r[0] ** 2 + r[1] ** 2, 3 / 2) * r[1]];
+ const dr = [...v];
+ return [dr, dv];
+}
+
+// initialize system
+let r = [-AU, 0];
+const theta = Math.atan2(r[1], r[0]);
+let v = [-v0 * Math.sin(theta), v0 * Math.cos(theta)];
+
+const t = Array.from({ length: 1001 }, (_, i) => i / 100 + 0.0); // years
+const yearSec = 365 * 24 * 3600;
+const dt = (t[1] - t[0]) * yearSec; // s
+const x4Plot = Array.from({ length: t.length }, () => 0);
+const y4Plot = Array.from({ length: t.length }, () => 0);
+
+// integrate using RK4!
+for (let i = 0; i < t.length; i++) {
+ const k1 = dR(r, v).map(x => x.map(y => y * dt));
+ const k2 = dR(r.map((ri, j) => ri + k1[0][j] / 2), v.map((vi, j) => vi + k1[1][j] / 2)).map(x => x.map(y => y * dt));
+ const k3 = dR(r.map((ri, j) => ri + k2[0][j] / 2), v.map((vi, j) => vi + k2[1][j] / 2)).map(x => x.map(y => y * dt));
+ const k4 = dR(r.map((ri, j) => ri + k3[0][j]), v.map((vi, j) => vi + k3[1][j])).map(x => x.map(y => y * dt));
+ r = r.map((ri, j) => ri + (k1[0][j] + 2 * k2[0][j] + 2 * k3[0][j] + k4[0][j]) / 6);
+ v = v.map((vi, j) => vi + (k1[1][j] + 2 * k2[1][j] + 2 * k3[1][j] + k4[1][j]) / 6);
+ x4Plot[i] = r[0];
+ y4Plot[i] = r[1];
+}
+
+// make data for plot
+var sun = { x: 0, y: 0 };
+const earth = { x: x4Plot.map(x => x / AU), y: y4Plot.map(y => y / AU) };
+const circle = { x: Array.from({ length: 1001 }, (_, i) => Math.cos(i / 100 * 2 * Math.PI)), y: Array.from({ length: 1001 }, (_, i) => Math.sin(i / 100 * 2 * Math.PI)) };
@@ -5323,76 +5341,77 @@ Next, the function dR takes the position r and velocity v of Earth as input and
Plotting the orbit
-Now that we have the data for the Sun's position, Earth's orbit, and the reference circle, we can plot them using Plotly.js.
-
- let traceSun = {
- x: [sun.x],
- y: [sun.y],
- mode: "markers",
- marker: {
- symbol: "star",
- size: 10,
- color: "gold",
- },
- name: "Sun",
- };
-
- const traceEarth = {
- x: earth.x,
- y: earth.y,
- mode: "lines",
- line: {
- color: "white"
- },
- name: "Earth",
- };
-
- const traceOrbit = {
- x: circle.x,
- y:circle.y,
- mode: "lines",
- line: {
- color: "crimson",
- dash: "dash"
- },
- name: "1 AU Circle",
- };
-
- const earthSunLayout = {
- title: "Earth-Sun Orbit",
- xaxis: {
- title: "x [AU]",
- range: [-1.1,1.1],
- showgrid: true,
- gridcolor: "rgba(255,255,255,0.5)",
- gridwidth: 1,
- zeroline: true,
- tickmode: "auto",
- nticks: 5,
- },
- yaxis: {
- title: "y [AU]",
- range: [-1.1,1.1],
- showgrid: true,
- gridcolor: "rgba(255,255,255,0.5)",
- gridwidth: 1,
- zeroline: false,
- tickmode: "auto",
- nticks: 5,
- },
- margin: {
- l: 50,
- r: 50,
- b: 50,
- t: 50,
- pad: 4,
- },
- paperbgcolor: "black",
- plotbgcolor: "black",
- };
- Plotly.newPlot("plot",[traceSun,traceEarth,traceOrbit], earthSunLayout);
-
-
+Now that we have the data for the Sun's position, Earth's orbit, and the reference circle, we can plot them using Plotly.js.
+
+
+ let traceSun = {
+ x: [sun.x],
+ y: [sun.y],
+ mode: "markers",
+ marker: {
+ symbol: "star",
+ size: 10,
+ color: "gold",
+ },
+ name: "Sun",
+ };
+
+ const traceEarth = {
+ x: earth.x,
+ y: earth.y,
+ mode: "lines",
+ line: {
+ color: "white"
+ },
+ name: "Earth",
+ };
+
+ const traceOrbit = {
+ x: circle.x,
+ y:circle.y,
+ mode: "lines",
+ line: {
+ color: "crimson",
+ dash: "dash"
+ },
+ name: "1 AU Circle",
+ };
+
+ const earthSunLayout = {
+ title: "Earth-Sun Orbit",
+ xaxis: {
+ title: "x [AU]",
+ range: [-1.1,1.1],
+ showgrid: true,
+ gridcolor: "rgba(255,255,255,0.5)",
+ gridwidth: 1,
+ zeroline: true,
+ tickmode: "auto",
+ nticks: 5,
+ },
+ yaxis: {
+ title: "y [AU]",
+ range: [-1.1,1.1],
+ showgrid: true,
+ gridcolor: "rgba(255,255,255,0.5)",
+ gridwidth: 1,
+ zeroline: false,
+ tickmode: "auto",
+ nticks: 5,
+ },
+ margin: {
+ l: 50,
+ r: 50,
+ b: 50,
+ t: 50,
+ pad: 4,
+ },
+ paper_bgcolor: "black",
+ plot_bgcolor: "black",
+ };
+ Plotly.newPlot("plot",[traceSun,traceEarth,traceOrbit], earthSunLayout);
+
+
Figure of 8 orbit
@@ -5413,78 +5432,78 @@ Next, the function dR takes the position r and velocity v of Earth as input and
The code for this simulation is very similar to the Earth-Sun orbit simulation, except that we now have three bodies instead of two. We also use a different set of initial conditions to generate the figure of 8 orbit.
-function deltaR(coords, masses, nBodies, G) {
- let x = coords[0];
- let y = coords[1];
- let vx = coords[2];
- let vy = coords[3];
+function deltaR(coords, masses, nBodies, G) {
+ let x = coords[0];
+ let y = coords[1];
+ let vx = coords[2];
+ let vy = coords[3];
- let delta = math.clone(coords);
+ let delta = math.clone(coords);
- for (let n = 0; n < nBodies; n++) {
- let xn = x[n];
- let yn = y[n];
- let deltaVx = 0.0;
- let deltaVy = 0.0;
+ for (let n = 0; n < nBodies; n++) {
+ let xn = x[n];
+ let yn = y[n];
+ let deltaVx = 0.0;
+ let deltaVy = 0.0;
- for (let i = 0; i < nBodies; i++) {
- if (i !== n) {
- let sep = Math.sqrt(Math.pow(xn - x[i], 2) + Math.pow(yn - y[i], 2)); // Euclidean distance
- deltaVx -= G * masses[i] * (xn - x[i]) / Math.pow(sep, 3);
- deltaVy -= G * masses[i] * (yn - y[i]) / Math.pow(sep, 3);
- }
- }
+ for (let i = 0; i < nBodies; i++) {
+ if (i !== n) {
+ let sep = Math.sqrt(Math.pow(xn - x[i], 2) + Math.pow(yn - y[i], 2)); // Euclidean distance
+ deltaVx -= G * masses[i] * (xn - x[i]) / Math.pow(sep, 3);
+ deltaVy -= G * masses[i] * (yn - y[i]) / Math.pow(sep, 3);
+ }
+ }
- delta[2][n] = deltaVx;
- delta[3][n] = deltaVy;
- }
+ delta[2][n] = deltaVx;
+ delta[3][n] = deltaVy;
+ }
- delta[0] = vx;
- delta[1] = vy;
+ delta[0] = vx;
+ delta[1] = vy;
- return delta;
-}
+ return delta;
+}
-function step(coords, masses, deltaT, nBodies = 3, G = 6.67408313131313e-11) {
- let k1 = math.multiply(deltaT, deltaR(coords, masses, nBodies, G));
- let k2 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k1, 0.5)), masses, nBodies, G));
- let k3 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k2, 0.5)), masses, nBodies, G));
- let k4 = math.multiply(deltaT, deltaR(math.add(coords, k3), masses, nBodies, G));
+function step(coords, masses, deltaT, nBodies = 3, G = 6.67408313131313e-11) {
+ let k1 = math.multiply(deltaT, deltaR(coords, masses, nBodies, G));
+ let k2 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k1, 0.5)), masses, nBodies, G));
+ let k3 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k2, 0.5)), masses, nBodies, G));
+ let k4 = math.multiply(deltaT, deltaR(math.add(coords, k3), masses, nBodies, G));
- coords = math.add(coords, math.multiply(math.add(k1, math.multiply(2.0, k2), math.multiply(2.0, k3), k4), 1/6));
+ coords = math.add(coords, math.multiply(math.add(k1, math.multiply(2.0, k2), math.multiply(2.0, k3), k4), 1/6));
- return coords;
-}
+ return coords;
+}
- // Initial conditions setup
- let M = [1, 1, 1];
- let x = [-0.97000436, 0.0, 0.97000436];
- let y = [0.24208753, 0.0, -0.24208753];
- let vx = [0.4662036850, -0.933240737, 0.4662036850];
- let vy = [0.4323657300, -0.86473146, 0.4323657300];
- let Ei = -1 / Math.sqrt(Math.pow(2 * 0.97000436, 2) + Math.pow(2 * 0.24208753, 2)) - 2 / Math.sqrt(Math.pow(0.97000436, 2) + Math.pow(0.24208753, 2)) + 0.5 * (math.sum(math.add(math.dotPow(vx, 2), math.dotPow(vy, 2))));
+ // Initial conditions setup
+ let M = [1, 1, 1];
+ let x = [-0.97000436, 0.0, 0.97000436];
+ let y = [0.24208753, 0.0, -0.24208753];
+ let vx = [0.4662036850, -0.933240737, 0.4662036850];
+ let vy = [0.4323657300, -0.86473146, 0.4323657300];
+ let Ei = -1 / Math.sqrt(Math.pow(2 * 0.97000436, 2) + Math.pow(2 * 0.24208753, 2)) - 2 / Math.sqrt(Math.pow(0.97000436, 2) + Math.pow(0.24208753, 2)) + 0.5 * (math.sum(math.add(math.dotPow(vx, 2), math.dotPow(vy, 2))));
- function linspace(start, stop, num) {
- const step = (stop - start) / (num - 1);
- return Array.from({length: num}, (_, i) => start + (step * i));
- }
+ function linspace(start, stop, num) {
+ const step = (stop - start) / (num - 1);
+ return Array.from({length: num}, (_, i) => start + (step * i));
+ }
- let coords = [x, y, vx, vy];
- const time = linspace(0, 6.3259, 1001);
- let deltaT = time[1] - time[0];
+ let coords = [x, y, vx, vy];
+ const time = linspace(0, 6.3259, 1001);
+ let deltaT = time[1] - time[0];
- let X = math.zeros(3, time.length).toArray();
- let Y = math.zeros(3, time.length).toArray();
- let VX = math.zeros(3, time.length).toArray();
- let VY = math.zeros(3, time.length).toArray();
+ let X = math.zeros(3, time.length).toArray();
+ let Y = math.zeros(3, time.length).toArray();
+ let VX = math.zeros(3, time.length).toArray();
+ let VY = math.zeros(3, time.length).toArray();
- for (let i = 0; i < time.length; i++) {
- coords = step(coords, M, deltaT, 3, 1);
- X.forEach((_, idx) => X[idx][i] = coords[0][idx]);
- Y.forEach((_, idx) => Y[idx][i] = coords[1][idx]);
- VX.forEach((_, idx) => VX[idx][i] = coords[2][idx]);
- VY.forEach((_, idx) => VY[idx][i] = coords[3][idx]);
- }
+ for (let i = 0; i < time.length; i++) {
+ coords = step(coords, M, deltaT, 3, 1);
+ X.forEach((_, idx) => X[idx][i] = coords[0][idx]);
+ Y.forEach((_, idx) => Y[idx][i] = coords[1][idx]);
+ VX.forEach((_, idx) => VX[idx][i] = coords[2][idx]);
+ VY.forEach((_, idx) => VY[idx][i] = coords[3][idx]);
+ }
@@ -5502,365 +5521,369 @@ Next, the function dR takes the position r and velocity v of Earth as input and
Animation?
-Now that we have time-series data, we need to animate it. We can use Plotly's animate function, as this does not force a full re-render, saving us some precious GPU and CPU cycles when we are trying to run this in the browser itself
-
- function plotClassicFunc() {
- var tailLength = 1;
- if (plotIndex < tailLength) {
- tailLength = 0;
- } else if (plotIndex > time.length) {
- plotIndex = 0;
- } else {
- tailLength = plotIndex - tailLength;
- }
-
- var currentIndex = plotIndex;
-
- try {
- time[currentIndex].toFixed(3);
- } catch (e) {
- currentIndex = 0;
- }
-
- const data = [
- {
- x: X[0].slice(tailLength, currentIndex),
- y: Y[0].slice(tailLength, currentIndex),
- mode: 'lines+markers',
- marker: {
- symbol: 'star',
- size: 8,
- line: { width: 0 },
- },
- line: {
- width: 2,
- },
- name: '',
- },
- {
- x: X[1].slice(tailLength, currentIndex),
- y: Y[1].slice(tailLength, currentIndex),
- mode: 'lines+markers',
- marker: {
- symbol: 'star',
- size: 8,
- line: { width: 0 },
- },
- line: {
- width: 2,
- },
- name: '',
- },
- {
- x: X[2].slice(tailLength, currentIndex),
- y: Y[2].slice(tailLength, currentIndex),
- mode: 'lines+markers',
- marker: {
- symbol: 'star',
- size: 8,
- line: { width: 0 },
- },
- line: {
- width: 2,
- },
- name: '',
- },
- ];
-
- // width: 1000, height: 400
- const layout = {
- title: '∞ Three-Body Problem: t = ' + time[currentIndex].toFixed(3),
- xaxis: {
- title: 'x',
- range: [-1.1,1.1]
- },
- yaxis: {
- title: 'y',
- scaleanchor: 'x',
- scaleratio: 1,
- range: [-0.5,0.5]
- },
- plotbgcolor: 'black',
- paperbgcolor: 'black',
- font: {
- color: 'white',
- },
- };
-
- try {
- Plotly.animate("plot", {
- data: data, layout: layout
- }, {
- staticPlot: true,
- transition: {
- duration: 0,
- },
- frame: {
- duration: 0,
- redraw: false,
- }
- });
- } catch (err) {
- Plotly.newPlot('plot', data, layout);
- }
-
-
- plotIndex += delay;
- if (plotClassic===true) {
- try {
- requestAnimationFrame(plotClassicFunc);
- }
- catch (err) {
- console.log(err)
- }
- }
-
- }
-
-
+Now that we have time-series data, we need to animate it. We can use Plotly's animate function, as this does not force a full re-render, saving us some precious GPU and CPU cycles when we are trying to run this in the browser itself
+
+
+ function plotClassicFunc() {
+ var tailLength = 1;
+ if (plotIndex < tailLength) {
+ tailLength = 0;
+ } else if (plotIndex > time.length) {
+ plotIndex = 0;
+ } else {
+ tailLength = plotIndex - tailLength;
+ }
+
+ var currentIndex = plotIndex;
+
+ try {
+ time[currentIndex].toFixed(3);
+ } catch (e) {
+ currentIndex = 0;
+ }
+
+ const data = [
+ {
+ x: X[0].slice(tailLength, currentIndex),
+ y: Y[0].slice(tailLength, currentIndex),
+ mode: 'lines+markers',
+ marker: {
+ symbol: 'star',
+ size: 8,
+ line: { width: 0 },
+ },
+ line: {
+ width: 2,
+ },
+ name: '',
+ },
+ {
+ x: X[1].slice(tailLength, currentIndex),
+ y: Y[1].slice(tailLength, currentIndex),
+ mode: 'lines+markers',
+ marker: {
+ symbol: 'star',
+ size: 8,
+ line: { width: 0 },
+ },
+ line: {
+ width: 2,
+ },
+ name: '',
+ },
+ {
+ x: X[2].slice(tailLength, currentIndex),
+ y: Y[2].slice(tailLength, currentIndex),
+ mode: 'lines+markers',
+ marker: {
+ symbol: 'star',
+ size: 8,
+ line: { width: 0 },
+ },
+ line: {
+ width: 2,
+ },
+ name: '',
+ },
+ ];
+
+ // width: 1000, height: 400
+ const layout = {
+ title: '∞ Three-Body Problem: t = ' + time[currentIndex].toFixed(3),
+ xaxis: {
+ title: 'x',
+ range: [-1.1,1.1]
+ },
+ yaxis: {
+ title: 'y',
+ scaleanchor: 'x',
+ scaleratio: 1,
+ range: [-0.5,0.5]
+ },
+ plot_bgcolor: 'black',
+ paper_bgcolor: 'black',
+ font: {
+ color: 'white',
+ },
+ };
+
+ try {
+ Plotly.animate("plot", {
+ data: data, layout: layout
+ }, {
+ staticPlot: true,
+ transition: {
+ duration: 0,
+ },
+ frame: {
+ duration: 0,
+ redraw: false,
+ }
+ });
+ } catch (err) {
+ Plotly.newPlot('plot', data, layout);
+ }
+
+
+ plotIndex += delay;
+ if (plotClassic===true) {
+ try {
+ requestAnimationFrame(plotClassicFunc);
+ }
+ catch (err) {
+ console.log(err)
+ }
+ }
+
+ }
+
+
"General" N-Body Solver
Show me the code!
-function step(coords, masses, deltaT, nBodies = 3, G = 6.67408313131313e-11) {
- let k1 = math.multiply(deltaT, deltaR(coords, masses, nBodies, G));
- let k2 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k1, 0.5)), masses, nBodies, G));
- let k3 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k2, 0.5)), masses, nBodies, G));
- let k4 = math.multiply(deltaT, deltaR(math.add(coords, k3), masses, nBodies, G));
-
- coords = math.add(coords, math.multiply(math.add(k1, math.multiply(2.0, k2), math.multiply(2.0, k3), k4), 1/6));
-
- return coords;
-}
-
-function detectCollisionsEscape(coords, deltaT, maxSep) {
- const [x, y, vx, vy] = coords;
- const V = vx.map((v, i) => Math.sqrt(v ** 2 + vy[i] ** 2));
- const R = V.map(v => v * deltaT);
- let collision = false, collisionInds = null, escape = false, escapeInd = null;
-
- for (let n = 0; n < x.length; n++) {
- const rn = R[n], xn = x[n], yn = y[n];
- for (let i = 0; i < x.length; i++) {
- if (i !== n) {
- const minSep = rn + R[i];
- const sep = Math.sqrt((xn - x[i]) ** 2 + (yn - y[i]) ** 2);
- if (sep < minSep) {
- collision = true;
- collisionInds = [n, i];
- } else if (sep > maxSep) {
- escape = true;
- escapeInd = n;
- return [collision, collisionInds, escape, escapeInd];
- }
- }
- }
- }
- return [collision, collisionInds, escape, escapeInd];
-}
-
-function nBodyStep(coords, masses, deltaT, maxSep, nBodies, G = 6.67408313131313e-11) { // Similar to our step function before, but keeping track of collisions
- coords = step(coords, masses, deltaT, nBodies, G); // Update the positions as we did before
- //console.log(detectCollisionsEscape(coords, deltaT, maxSep));
- let [collision, collisionInds, escape, escapeInd] = detectCollisionsEscape(coords, deltaT, maxSep); // Detect collisions/escapes
-
-
- if (collision) { // Do inelastic collision and delete extra body (2 -> 1)
- const [i1, i2] = collisionInds;
- const [x1, x2] = [coords[0][i1], coords[0][i2]];
- const [y1, y2] = [coords[1][i1], coords[1][i2]];
- const [vx1, vx2] = [coords[2][i1], coords[2][i2]];
- const [vy1, vy2] = [coords[3][i1], coords[3][i2]];
- const [px1, px2] = [masses[i1] * vx1, masses[i2] * vx2];
- const [py1, py2] = [masses[i1] * vy1, masses[i2] * vy2];
- const px = px1 + px2;
- const py = py1 + py2;
- const newM = masses[i1] + masses[i2];
- const vfx = px / newM;
- const vfy = py / newM;
- coords[0][i1] = (x1 * masses[i1] + x2 * masses[i2]) / (masses[i1] + masses[i2]); // Center of mass
- coords[1][i1] = (y1 * masses[i1] + y2 * masses[i2]) / (masses[i1] + masses[i2]);
- coords[2][i1] = vfx;
- coords[3][i1] = vfy;
- coords[0].splice(i2, 1);
- coords[1].splice(i2, 1);
- coords[2].splice(i2, 1);
- coords[3].splice(i2, 1);
- masses[i1] = newM;
- masses.splice(i2, 1);
- nBodies--;
- }
- // Could also implement condition for escape where we stop calculating forces but I'm too lazy for now
- return [coords, masses, nBodies, collision, collisionInds, escape, escapeInd];
-}
-
-function uniform(min, max) {
- return Math.random() * (max - min) + min;
-}
-
-function deepCopyCoordsArray(arr) {
- return arr.map(innerArr => innerArr.slice());
-}
-
-function genNBodyResults(nBodies, tStop, nTPts, nBodiesStop = 10, G = 6.67408313131313e-11) {
-
- var btn = document.getElementById("startSim3");
- // Set button text to Solving
- var prevText = btn.innerHTML;
- btn.innerHTML = "Solving...";
-
- let coords = [Array(nBodies).fill(0), Array(nBodies).fill(0), Array(nBodies).fill(0), Array(nBodies).fill(0)];
- const Mstar = 2e30;
- const Mp = Mstar / 1e4;
-
- for (let i = 0; i < nBodies; i++) { // Initialize coordinates on ~Keplerian orbits
- let accept = false;
- let r = null;
- while (!accept) { // Prevent a particle from spawning within 0.2 AU too close to "star"
- r = Math.random() * 2 * 1.5e11; // Say radius of 2 AU
- if (r / 1.5e11 > 0.2) {
- accept = true;
- }
- }
- const theta = uniform(0, 2 * Math.PI);
- const x = r * Math.cos(theta);
- const y = r * Math.sin(theta);
- const v = Math.sqrt(G * Mstar / r);
- const perturbedV = v + v / 1000 * uniform(-1, 1); // Perturb the velocities ever so slightly
- const vTheta = Math.atan2(y, x);
- coords[0][i] = x;
- coords[1][i] = y;
- coords[2][i] = -perturbedV * Math.sin(vTheta);
- coords[3][i] = perturbedV * Math.cos(vTheta);
- }
-
- //console.log('Initial coords:', coords);
-
-
- let masses = Array(nBodies).fill(Mp); // Initialize masses
- masses[0] = Mstar; // Make index one special as the central star
- coords[0][0] = 0;
- coords[1][0] = 0;
- coords[2][0] = 0;
- coords[3][0] = 0; // Initialize central star at origin with no velocity
- const yearSec = 365 * 24 * 3600;
- const time = Array.from({ length: nTPts }, (_, i) => i * tStop / (nTPts - 1) * yearSec); // Years -> s
- let t = time[0];
- const deltaT = time[1] - time[0];
- let tInd = 0;
- const coordsRecord = [deepCopyCoordsArray(coords)];
- const massRecord = [masses.slice()]; // Initialize records with initial conditions
-
-
- while (tInd < nTPts && nBodies > nBodiesStop) {
- //console.log('Initial coords:', coords);
- [coords, masses, nBodies] = nBodyStep(coords, masses, deltaT, 10 * 1.5e11, nBodies, G); // Update
- coordsRecord.push(deepCopyCoordsArray(coords));
- massRecord.push(masses.slice()); // Add to records
- tInd++;
- t = time[tInd];
- //console.log(`currently at t = ${(t / yearSec).toFixed(2)} years\r`);
- }
- console.log(`final time = ${time[tInd] / yearSec} years with ${nBodies} bodies remaining`);
-
- // Set button text to Start Simulation
- btn.innerHTML = prevText;
-
- return [coordsRecord, massRecord, time.slice(0, tInd + 1)];
-}
-
-
- var [coordsRecordR, _, tR] = genNBodyResults(256,1,1001);
- //console.log(coordsRecordR);
- const yearSec = 365 * 24 * 3600;
-
- function createFrame(coordsR) {
- if (!coordsR || !coordsR[0] || !coordsR[1]) {
- return [];
- }
-
- const traceCentralStar = {
- x: [coordsR[0][0] / 1.5e11],
- y: [coordsR[1][0] / 1.5e11],
- mode: 'markers',
- type: 'scatter',
- name: 'Central star',
- marker: { color: 'gold', symbol: 'star', size: 10 },
- };
-
- const xCoords = coordsR[0].slice(1).map(x => x / 1.5e11);
- const yCoords = coordsR[1].slice(1).map(y => y / 1.5e11);
-
- const traceOtherBodies = {
- x: xCoords,
- y: yCoords,
- mode: 'markers',
- type: 'scatter',
- name: '',
- marker: { color: 'dodgerblue', symbol: 'circle', size: 2 },
- };
-
- return [traceCentralStar, traceOtherBodies];
- }
-
-
- function createLayout(i) {
- return {
- title: {
- text: `N-Body Problem: t = ${Number(t[i] / yearSec).toFixed(3)} years`,
- x: 0.03,
- y: 0.97,
- xanchor: 'left',
- yanchor: 'top',
- font: { size: 14 },
- },
- xaxis: { title: 'x [AU]', range: [-2.1, 2.1] },
- yaxis: { title: 'y [AU]', range: [-2.1, 2.1], scaleanchor: 'x', scaleratio: 1 },
- showlegend: false,
- margin: { l: 60, r: 40, t: 40, b: 40 },
- width: 800,
- height: 800,
- plot_bgcolor: 'black',
- };
-}
-
- function animateNBodyProblem() {
- const nFrames = tR.length;
-
- for (let i = 0; i < nFrames; i++) {
- const frameData = createFrame(coordsRecordR[i]);
- const layout = createLayout(i);
- //Plotly.newPlot(plotDiv, frameData, layout);
- try {
- Plotly.animate("plot", {
- data: frameData, layout: layout
- }, {
- staticPlot: true,
- transition: {
- duration: 0,
- },
- frame: {
- duration: 0,
- redraw: false,
- }
- });
- } catch (err) {
- Plotly.newPlot('plot', frameData, layout);
- }
- }
-}
-
-animateNBodyProblem();
+function step(coords, masses, deltaT, nBodies = 3, G = 6.67408313131313e-11) {
+ let k1 = math.multiply(deltaT, deltaR(coords, masses, nBodies, G));
+ let k2 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k1, 0.5)), masses, nBodies, G));
+ let k3 = math.multiply(deltaT, deltaR(math.add(coords, math.multiply(k2, 0.5)), masses, nBodies, G));
+ let k4 = math.multiply(deltaT, deltaR(math.add(coords, k3), masses, nBodies, G));
+
+ coords = math.add(coords, math.multiply(math.add(k1, math.multiply(2.0, k2), math.multiply(2.0, k3), k4), 1/6));
+
+ return coords;
+}
+
+function detectCollisionsEscape(coords, deltaT, maxSep) {
+ const [x, y, vx, vy] = coords;
+ const V = vx.map((v, i) => Math.sqrt(v ** 2 + vy[i] ** 2));
+ const R = V.map(v => v * deltaT);
+ let collision = false, collisionInds = null, escape = false, escapeInd = null;
+
+ for (let n = 0; n < x.length; n++) {
+ const rn = R[n], xn = x[n], yn = y[n];
+ for (let i = 0; i < x.length; i++) {
+ if (i !== n) {
+ const minSep = rn + R[i];
+ const sep = Math.sqrt((xn - x[i]) ** 2 + (yn - y[i]) ** 2);
+ if (sep < minSep) {
+ collision = true;
+ collisionInds = [n, i];
+ } else if (sep > maxSep) {
+ escape = true;
+ escapeInd = n;
+ return [collision, collisionInds, escape, escapeInd];
+ }
+ }
+ }
+ }
+ return [collision, collisionInds, escape, escapeInd];
+}
+
+function nBodyStep(coords, masses, deltaT, maxSep, nBodies, G = 6.67408313131313e-11) { // Similar to our step function before, but keeping track of collisions
+ coords = step(coords, masses, deltaT, nBodies, G); // Update the positions as we did before
+ //console.log(detectCollisionsEscape(coords, deltaT, maxSep));
+ let [collision, collisionInds, escape, escapeInd] = detectCollisionsEscape(coords, deltaT, maxSep); // Detect collisions/escapes
+
+
+ if (collision) { // Do inelastic collision and delete extra body (2 -> 1)
+ const [i1, i2] = collisionInds;
+ const [x1, x2] = [coords[0][i1], coords[0][i2]];
+ const [y1, y2] = [coords[1][i1], coords[1][i2]];
+ const [vx1, vx2] = [coords[2][i1], coords[2][i2]];
+ const [vy1, vy2] = [coords[3][i1], coords[3][i2]];
+ const [px1, px2] = [masses[i1] * vx1, masses[i2] * vx2];
+ const [py1, py2] = [masses[i1] * vy1, masses[i2] * vy2];
+ const px = px1 + px2;
+ const py = py1 + py2;
+ const newM = masses[i1] + masses[i2];
+ const vfx = px / newM;
+ const vfy = py / newM;
+ coords[0][i1] = (x1 * masses[i1] + x2 * masses[i2]) / (masses[i1] + masses[i2]); // Center of mass
+ coords[1][i1] = (y1 * masses[i1] + y2 * masses[i2]) / (masses[i1] + masses[i2]);
+ coords[2][i1] = vfx;
+ coords[3][i1] = vfy;
+ coords[0].splice(i2, 1);
+ coords[1].splice(i2, 1);
+ coords[2].splice(i2, 1);
+ coords[3].splice(i2, 1);
+ masses[i1] = newM;
+ masses.splice(i2, 1);
+ nBodies--;
+ }
+ // Could also implement condition for escape where we stop calculating forces but I'm too lazy for now
+ return [coords, masses, nBodies, collision, collisionInds, escape, escapeInd];
+}
+
+function uniform(min, max) {
+ return Math.random() * (max - min) + min;
+}
+
+function deepCopyCoordsArray(arr) {
+ return arr.map(innerArr => innerArr.slice());
+}
+
+function genNBodyResults(nBodies, tStop, nTPts, nBodiesStop = 10, G = 6.67408313131313e-11) {
+
+ var btn = document.getElementById("startSim3");
+ // Set button text to Solving
+ var prevText = btn.innerHTML;
+ btn.innerHTML = "Solving...";
+
+ let coords = [Array(nBodies).fill(0), Array(nBodies).fill(0), Array(nBodies).fill(0), Array(nBodies).fill(0)];
+ const Mstar = 2e30;
+ const Mp = Mstar / 1e4;
+
+ for (let i = 0; i < nBodies; i++) { // Initialize coordinates on ~Keplerian orbits
+ let accept = false;
+ let r = null;
+ while (!accept) { // Prevent a particle from spawning within 0.2 AU too close to "star"
+ r = Math.random() * 2 * 1.5e11; // Say radius of 2 AU
+ if (r / 1.5e11 > 0.2) {
+ accept = true;
+ }
+ }
+ const theta = uniform(0, 2 * Math.PI);
+ const x = r * Math.cos(theta);
+ const y = r * Math.sin(theta);
+ const v = Math.sqrt(G * Mstar / r);
+ const perturbedV = v + v / 1000 * uniform(-1, 1); // Perturb the velocities ever so slightly
+ const vTheta = Math.atan2(y, x);
+ coords[0][i] = x;
+ coords[1][i] = y;
+ coords[2][i] = -perturbedV * Math.sin(vTheta);
+ coords[3][i] = perturbedV * Math.cos(vTheta);
+ }
+
+ //console.log('Initial coords:', coords);
+
+
+ let masses = Array(nBodies).fill(Mp); // Initialize masses
+ masses[0] = Mstar; // Make index one special as the central star
+ coords[0][0] = 0;
+ coords[1][0] = 0;
+ coords[2][0] = 0;
+ coords[3][0] = 0; // Initialize central star at origin with no velocity
+ const yearSec = 365 * 24 * 3600;
+ const time = Array.from({ length: nTPts }, (_, i) => i * tStop / (nTPts - 1) * yearSec); // Years -> s
+ let t = time[0];
+ const deltaT = time[1] - time[0];
+ let tInd = 0;
+ const coordsRecord = [deepCopyCoordsArray(coords)];
+ const massRecord = [masses.slice()]; // Initialize records with initial conditions
+
+
+ while (tInd < nTPts && nBodies > nBodiesStop) {
+ //console.log('Initial coords:', coords);
+ [coords, masses, nBodies] = nBodyStep(coords, masses, deltaT, 10 * 1.5e11, nBodies, G); // Update
+ coordsRecord.push(deepCopyCoordsArray(coords));
+ massRecord.push(masses.slice()); // Add to records
+ tInd++;
+ t = time[tInd];
+ //console.log(`currently at t = ${(t / yearSec).toFixed(2)} years\r`);
+ }
+ console.log(`final time = ${time[tInd] / yearSec} years with ${nBodies} bodies remaining`);
+
+ // Set button text to Start Simulation
+ btn.innerHTML = prevText;
+
+ return [coordsRecord, massRecord, time.slice(0, tInd + 1)];
+}
+
+
+ var [coordsRecordR, _, tR] = genNBodyResults(256,1,1001);
+ //console.log(coordsRecordR);
+ const yearSec = 365 * 24 * 3600;
+
+ function createFrame(coordsR) {
+ if (!coordsR || !coordsR[0] || !coordsR[1]) {
+ return [];
+ }
+
+ const traceCentralStar = {
+ x: [coordsR[0][0] / 1.5e11],
+ y: [coordsR[1][0] / 1.5e11],
+ mode: 'markers',
+ type: 'scatter',
+ name: 'Central star',
+ marker: { color: 'gold', symbol: 'star', size: 10 },
+ };
+
+ const xCoords = coordsR[0].slice(1).map(x => x / 1.5e11);
+ const yCoords = coordsR[1].slice(1).map(y => y / 1.5e11);
+
+ const traceOtherBodies = {
+ x: xCoords,
+ y: yCoords,
+ mode: 'markers',
+ type: 'scatter',
+ name: '',
+ marker: { color: 'dodgerblue', symbol: 'circle', size: 2 },
+ };
+
+ return [traceCentralStar, traceOtherBodies];
+ }
+
+
+ function createLayout(i) {
+ return {
+ title: {
+ text: `N-Body Problem: t = ${Number(t[i] / yearSec).toFixed(3)} years`,
+ x: 0.03,
+ y: 0.97,
+ xanchor: 'left',
+ yanchor: 'top',
+ font: { size: 14 },
+ },
+ xaxis: { title: 'x [AU]', range: [-2.1, 2.1] },
+ yaxis: { title: 'y [AU]', range: [-2.1, 2.1], scaleanchor: 'x', scaleratio: 1 },
+ showlegend: false,
+ margin: { l: 60, r: 40, t: 40, b: 40 },
+ width: 800,
+ height: 800,
+ plot_bgcolor: 'black',
+ };
+}
+
+ function animateNBodyProblem() {
+ const nFrames = tR.length;
+
+ for (let i = 0; i < nFrames; i++) {
+ const frameData = createFrame(coordsRecordR[i]);
+ const layout = createLayout(i);
+ //Plotly.newPlot(plotDiv, frameData, layout);
+ try {
+ Plotly.animate("plot", {
+ data: frameData, layout: layout
+ }, {
+ staticPlot: true,
+ transition: {
+ duration: 0,
+ },
+ frame: {
+ duration: 0,
+ redraw: false,
+ }
+ });
+ } catch (err) {
+ Plotly.newPlot('plot', frameData, layout);
+ }
+ }
+}
+
+animateNBodyProblem();
Playground
+
+
+
-
+
+
-
+
+
-
+
+
+
-
+
+
+
+
+
+
-
+
+
-
+
+