<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kresna Devara on Medium]]></title>
        <description><![CDATA[Stories by Kresna Devara on Medium]]></description>
        <link>https://medium.com/@kresna-devara?source=rss-5fcbba73ef2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*MWezGm-J5vZGhTGEceeD4g.png</url>
            <title>Stories by Kresna Devara on Medium</title>
            <link>https://medium.com/@kresna-devara?source=rss-5fcbba73ef2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 13:11:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kresna-devara/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Side Channel Attack (SCA) on AES — Part 2]]></title>
            <link>https://kresna-devara.medium.com/side-channel-attack-sca-on-aes-part-2-fb303cc62b25?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb303cc62b25</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[side-channel-attacks]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[hardware]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Mon, 04 Mar 2024 13:41:59 GMT</pubDate>
            <atom:updated>2024-03-04T14:11:15.093Z</atom:updated>
            <content:encoded><![CDATA[<h3>Side Channel Attack (SCA) on AES — Part 2</h3><p>Hello !!! after previous post I talked about introduction SCA on AES from setup environment, generate traces with simulator and do a Simple Power Analysis on AES. In this post I will tell you how to break AES key. Before we go further I will tell the short explanation about DPA and CPA. Let’s get started………</p><h3>DPA and CPA</h3><p>what is DPA and CPA? DPA is Differential Power Analysis, I quote it from Wikipedia:</p><blockquote><strong>Differential power analysis</strong> (<strong>DPA</strong>) is a <a href="https://en.wikipedia.org/wiki/Side-channel_attack">side-channel attack</a> which involves statistically analyzing power consumption measurements from a <a href="https://en.wikipedia.org/wiki/Cryptosystem">cryptosystem</a>. The attack exploits biases varying power consumption of microprocessors or other hardware while performing operations using secret keys</blockquote><p>by statistically analyze power consumption of hardware we can find the secret/key is used in the process. How come it&#39;s possible to analyze the power consumption? Every input we gave, it will make the hardware run the process like XOR, AND, SHIFT, OR, and etc. The register value always change due to the variation of the process.</p><p>One of the famous power leakage model used is Hamming Weight it counts number of bit 1 in intermediate state. For example you have input: 0xAB ^ 0x12 = 0xB9. If we convert 0xB9 to binary it’s equal to: 10111001, so the hamming weight of 0xB9 is 5. With this technique we can predict the secret by grouping possibility of guess bit per bit.</p><p>Different from DPA that analyze the possibility bit per bit by grouping guesses, CPA is more straight forward and more statistical. That’s why the name is CPA, Correlation Power Analysis. So we will use correlation between the real power consumption we captured from Oscilloscope (Power/Current) and power model we used in statistic (Hamming Weight). To make it simple if we do operation 0xAB ^ 0x12 = 0xB9 (HW=5) the power we captured in Oscilloscope will be moderated, and if we do operation 0xA5 ^ 0x5A = 0xFF (HW=9) the power in Oscilloscope will be very high, and if the result is 0x00 the power will be low.</p><p>Let’s say you want to find AES Key, with the same/fixed key you must give different input (plaintext) and you need to make guesses of key from 0x00 to 0xFF and find with what byte guess you get high correlation between your power model and real power consumption. If the correlation high it might be the key used in the process. Of course you will not do it manually one by one, you need some formula to do the correlation. That’s why in the CPA it used Pearson Correlation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/0*-AKxDa8FaHojlbyh" /></figure><p>You can find more detail about this formula in <a href="https://en.wikipedia.org/wiki/Pearson_correlation_coefficient">Wikipedia</a>. I will not tell you all the detail about this. But, if you are interested to read more detail about how to use Pearson Correlation in CPA you also can read it in <a href="https://wiki.newae.com/Correlation_Power_Analysis">Chipwhisperer Wiki</a>, this is one of the best resource to learn Side Channel Attack. Ok it’s enough for introduction I don’t want to tell too many theory because maybe it can be boring for some people 😛</p><h3>CPA with Kresca Module</h3><p>From previous post I already told you how to generate AES traces with the simulator and save it in Eshard Tracesheader set (ETS). And now we will use the traces again to attack the real key of AES. Before we go further don’t forget to activate your SCA virutal environment. After that, open this file from my github repository</p><p>kresca → Example → AES → AES Attack.ipynb</p><h4>Import Library and Plot Traces</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqYo6Nadn342rCqj6iqWRQ.png" /></figure><p>Run the cell to import some needed library and kresca module. Import the traces from previous post “TinyAES_1k.ets” and see the content of traces: 1000 sample traces with 3 metadatas (plaintext, key, and ciphertext).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k4ZImWizul0timPs0S1bpw.png" /></figure><p>if you want to plot inline in your notebook, put extra parameter “inline=True” otherwise it will generate new window dedicated for the curve only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*n-f1PHxvRqMd0Rpw1VKomg.png" /></figure><h4>Make Selection Functions</h4><p>To do CPA in AES, we must choose good intermediate area to retrieve the master key. There are several popular intermediate area in AES:</p><ul><li>First Add Round Key → Plaintext^Key</li><li>First Sub Bytes → Sbox[Plaintext^Key]</li><li>Last Add Round Key → Ciphertext^Key</li><li>Last Sub Bytes → Sbox[Ciphertext^Key]</li></ul><p>First means we use key from first round, last means we use last key schedule from the last round (Ex. 10th round AES-128). There are another intermediate function like Mix Column Attack or Delta R Last, but I will not explain it in this post. You also must guess where is the first or last area to get the leakage, that’s why SPA is the important process before you go to the CPA.</p><p>In the add round key you will find the correlation between hamming weight of addroundkey plaintext/ciphertext ^ key with the real measurement (Power/EM) in the real product. In this case, your real measurements comes from simulator result. In Sub bytes intermediate function you put the plaintext/ciphetext ^ Key to the Sbox first. It’s better to choose non-linear intermediate function which is go into the Substation Box first, So if the correlation happen between the guess model and the real product it will only have 1 possibility outcome. If we use linear function like add round key, due to hamming Weight model, the guess input from 0–255 can get more similar Hamming Weight (0~8) value.</p><p>In the Kresca Module, I used existing eShard scared selection function. You can just use it or later you can create your own customize selection function for others algorithm.</p><p>Let’s construct the selection function into 1 list. Then later we can just run it with single shot to get all the result without doing it one bye one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zs_xNahXunhqazGGm8OgGQ.png" /></figure><h4>Make and Run Attack Object</h4><p>After we made selection functions, We need to make an attack object. First, you need to used NonProfileAttack object. The simplest things you need to give to this object are traces file and the selection function list. After that, you can just call run and it will run all of your selection functions in one shot.</p><p>*(You might not get the loading bar below, because I already put the extra library in scared to give loading bar in run process, but trust me the rest is same)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQX8jKcRSc3HQV-pNQyoqQ.png" /></figure><p>Actually in NonProfileAttack object you can give more optional parameter other than this two, you can see in this image bellow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*58rBX8dL4xFKoj22zthkWg.png" /></figure><ul><li>distinguisher → is how you compute the CPA, default use CPA means used Pearson Correlation formula</li><li>model → is the model type to guess the intermediate function, default used Hamming Weight model</li><li>discriminant → is how you make a ‘rank/score’ from your computation result (your correlation positive/negative)</li><li>frame → is to select the specific point from your traces, you can put specific point by use range(X, Y) to this parameter.</li><li>preprocess → preprocess method for the traces. You can use it if you want to do something to your traces before you use it for computation (Ex. filter, standardize, product between point, etc.) We can use preprocess to do second order attack</li></ul><p>You can find more detail about this parameter in <a href="https://eshard.gitlab.io/scared/api_reference/index.html">eShard scared documentation</a>.</p><p>After you finished to run the attack object you can just run the report. It will give you all the score report for all your selection functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxqkUbH46QMKRb09uaasDw.png" /></figure><p>You also can run show_result() to see the plot of your leakage. Left plot shows where the leakage is, x-axis show sample points and y-axis is the correlation score. Right plot shows convergence scores where x-axis shows how many traces you need and y-axis shows the the correlation scores itself. The more traces you used the more confident score you will get.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*UcezFf0xCCUkxfdt5PTsoQ.png" /></figure><p>You can see in the first add round key, guess 0x00 and 0xFF have high correlation. However, the correlation is the opposite. It means if you use linear intermediate function there is a chance you will have more then 1 guess which has similar correlation. If you only have 2 guesses with high correlation and the correlation is opposite, you can change the discriminant in previous parameter to nanmax (default maxabs), then you will just count the guess with the positive correlation as the highest rank.</p><p>Contrast with the first add round key, the first sub bytes only has 1 guess with the high correlation score. With this result in the real world (where you don’t know what the real key is) you can confident enough with your guess as the real key. That’s why non-linear intermediate function is better, whatever input you give to the function, the correlation is always consistent to 1 guess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*M6-KaiB2bhWQj7TVQTI-8w.png" /></figure><p>You can see from the last round both add round key and sub bytes have same behavior with the first round. So you can choose to attack first or last round, it depends on situation. If you are attacking the first round you can use the key as a master key directly. But, if you are attacking the last round to get the master key, you need to do a reverse key schedule to get the master key.</p><p>Huala it’s done you already can get the AES Key !!!! FYI in the mobile SIM Card, one of the most popular algorithm for authentication is Milenage. And you know what? Milenage Algorithm is based on AES !!!! So with this knowledge you can get the secret of every SIM Card and clone it 😃 But of course the good SIM Card company will protect it with anti Side Channel Attack Right 😛 But don’t worry there will be another company who don’t know about this and you can try it there😆</p><blockquote><em>— Still Stay Tuned And Wait For The Next Post Thank You !!! —</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb303cc62b25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Side Channel Attack (SCA) on AES — Part 1]]></title>
            <link>https://kresna-devara.medium.com/side-channel-attack-sca-on-aes-part-1-ca066fe362c4?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca066fe362c4</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[side-channel-attacks]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Fri, 02 Feb 2024 09:05:30 GMT</pubDate>
            <atom:updated>2024-02-02T09:05:30.455Z</atom:updated>
            <content:encoded><![CDATA[<h3>Side Channel Attack (SCA) on AES — Part 1</h3><p>Hello !!! after a long time postpone from Medium, I want to continue my post about SCA (it’s been delayed for 2 years 😄). In previous post, I talked about the SCA, what is SCA and the example of SCA by using Chipwhisperer Nano. And very very long time ago I also talked about AES, what is AES, how the AES algo works and how popular the algo is. And now I want to tell you how to break the AES through the Side Channel Attack on Embedded System. In this post, I also will tell you how to use Hardware Simulator that can generate power traces, so you don’t need to care about having a Hardware or an Oscilloscope setup to collect the traces !!! It’s interesting right 😃 Sooo, let’s get started…..</p><h3><strong>Requirements</strong></h3><h4>1. Create Python Environment</h4><p>First of all, what you need is Python. I assume you are already familiar with Python environment. It’s better to create new environment, you can use native python and create virtual env, or you can use Ananconda/Miniconda. You also can follow my environment by cloning my repository in: <a href="https://github.com/kresdev/kresca">https://github.com/kresdev/kresca</a> and follow this step:</p><ol><li>Install Python (3.12 is recommended)</li><li>Create virtual environment: python -m venv scaenv</li><li>Activate virtual environment(Windows): scaenv\Scripts\activate</li><li>Install all requirements package: pip install -r requirements.txt</li></ol><h4>2. Install Rainbow Simulator</h4><p>Rainbow is one of the hardware simulator based on Unicorn Engine (QEMU) developed by Ledger Donjon. Based on the GitHub page Rainbow aims to provide an easy scripting interface to loosely emulate embedded binaries, trace them to perform side-channels, and simulate fault injections. You can follow this link and install in under your python environment</p><p><a href="https://github.com/Ledger-Donjon/rainbow">GitHub - Ledger-Donjon/rainbow: Makes Unicorn traces. Generic Side-Channel and Fault Injection simulator</a></p><h4>3. KRESCA Module and Example 😄</h4><p>To make it easy for all of you I create a Python module (mostly based on eshard-scared) and examples for SCA from collecting traces with simulator, visualize the traces, synchronization, reverse/leakage assesment, attack, an so oooon…. You can find this module and example in my github</p><p><a href="https://github.com/kresdev/kresca">GitHub - kresdev/kresca: Side Channel Analysis Tools</a></p><p>It’s not finished yet, so this is not installable. There are some dependencies you need: matplotlib, numpy, pandas, estraces, scared, and vispy (all included in requirements.txt). You can run this module by pointing your directory to this module path. Or if you can run the module through the example folder</p><h3>Generate Traces with Simulator</h3><p>After finish setup the environment, the next step is generate traces with Rainbow Simulator. The AES.elf provided is based on open source <a href="https://github.com/kokke/tiny-AES-c">Tiny AES</a>, you can take a look to the source code and learn how it works. Ok next, to start run simulator you can go to the</p><p>kresca → Example → Simulator → AES → GenerateAES.ipynb</p><p>This is how it looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*qZryrydHTunp6iukCuPAnw.png" /></figure><p>1. First, you must import some important library.</p><p>2. Create a rainbow simulator object. Because I compiled the AES library with Cortex M0 chip I use rainbow_cortexm as an object. Optionally, you can create your elf/hex file with different chip and use different microcontroller.</p><p>3. Create function to run AES. To run AES in TinyAES you need to run two function. First, you need to run key schedule function (parameter key). Second, you need to run ECB_indp_crypto to do encryption (parameter 1 buffer input, parameter 2 buffer output). Rainbow will generate the Hamming Weight Power Model based on register. I add some noise to make it more real 😜.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*U7xcw7yAIFxxA8ZusSA2gw.png" /></figure><p>4. You can use fix key and plaintext first for testing purpose.</p><p>5. Or you can start to collect traces by making randomize plaintext. The power traces will be saved in traces list.</p><p>6. Then plot the traces with kresca visualization (Thankyou Vispy!!!). You can shift, zoom-in/out, drag the traces, hide the traces, etc. with kresca.plot (there are some secret shortcut to shift traces position and hide the traces 😝)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*SQJiKrTnFC24Wa2BxNwYcA.png" /></figure><p>7. After see the traces you can collect more traces and make the complete traces file (traces point and metadata plaintext, key, ciphertext) with estraces. Optionally, you also can cut the traces sample points based on your need.</p><p>Hualaa it’s done you can continue to the next step 😍</p><h3>Simple Power Analysis (SPA) on AES</h3><p>After making a completed traces in ets file. The next step is to analyze it more detail. This technique name is Simple Power Analysis (SPA). With this you can find in what area your target is. First you can open the example in:</p><p>kresca → Example → AES → AES Simple Power Analysis (SPA).ipynb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*RORCe8McWZ1EdwnlfBn6jg.png" /></figure><p>1. First, same as before. You need to import some important libraries.</p><p>2. You can import the traces file from previous step by using estraces library (you also can read from different type of traces file like .trs or bin file)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*oG_D-ljpF35oNO00II4a1g.png" /></figure><p>3. You see open the traces with kresca.plot first or you can see the traces with matplotlib. As seen from picture above, you can find your AES contains two function first is Key Schedule and second is the main AES process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*Ljh3zHuY0uGqonWIeVjRcw.png" /></figure><p>4. If you zoom-in to the first round of AES, you will see this pattern. From the traces, you can find the repeated pattern and found the specific process like Add Round Key, Sub Bytes, Shift Rows, and Mix Column. This is what we want !!! our target will be in AES round 1 Sub Bytes !!!</p><p>Huala it’s done you already identified the target area. So now you can focus on this area only, or….. you still interested to find another area in last round? it’s up to you 😃</p><blockquote>— So let’s go to the next part of SCA on AES, Stay Tuned and Thank You !!! —</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca066fe362c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Side Channel Attack (SCA)]]></title>
            <link>https://kresna-devara.medium.com/side-channel-attack-sca-afa393d457d7?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/afa393d457d7</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[side-channel-attacks]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Sat, 02 Jan 2021 08:35:13 GMT</pubDate>
            <atom:updated>2021-01-02T14:02:08.508Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, in the previous post I have talked about <a href="https://medium.com/@kresna.devara/cryptography-advanced-encryption-standard-aes-5c09b0da76e4"><strong>AES</strong></a><strong>. </strong>In this post I will talk about the something interesting about breaking a cryptographic algorithm. There are two methods to break a cryptographic algorithm. The first one with cryptanalysis like in the <a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10"><strong>Vigenere </strong></a>and <a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a"><strong>Caesar </strong></a>and another one is using side channel leakage. <strong>DES </strong>and <strong>AES </strong>are very hard to break with cryptanalysis methods. However, this algorithm still can be broken using a leakage from their side channel device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*PdlZI4J7ySHFRs86UI77KQ.png" /></figure><h3>Attack on Cryptographic Device</h3><p>There are a lot of cryptographic device that implements a cryptographic algorithm and stores a cryptographic key. For example in identification card, payment card, mobile phone, multimedia, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*Y61wW5Tt0DqMui9y2vWw6g.png" /></figure><p>The cryptographic device is used as tools to make sure data integrity. However, the cryptographic device might have a weakness from the electronics components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*FCJNRxGcwUxJK7lKSaNBLw.png" /></figure><p>A good algorithm is not enough to secure a cryptographic devices. Another way to break a cryptographic device might still open.</p><p>There are two ways to performing attacks:</p><p><strong>Active (Perturbate and Conclude) or Fault Attack:</strong></p><ul><li>Disturbance some variables in order to obtain information on sensitive values.</li><li>Disturbance of code execution to force the chip to execute some forbidden operations or to skip some sensitive process.</li><li>Use the physical properties of the device components: electrical disturbance (glitch), light, heat, electromagnetic radiations.</li></ul><p><strong>Passive (Observe and Infer) or Side Channel Analysis:</strong></p><ul><li>Observe the behavior of the chip.</li><li>Use the physical properties of the device components: timing variation, power consumption, radio frequency field, electromagnetic radiations.</li></ul><p>There are Three ways of physically attacks on cryptographic device:</p><p><strong>Non Invasive Attack</strong>: no modification to device</p><ul><li>Can be performed with Power , Timing , Radio Frequency Analysis or Attack.</li></ul><p><strong>Semi Invasive Attack</strong>: open package (the packaging is modified, the chip is exposed), no direct contact to device.</p><ul><li>Can be performed with Electromagnetic Radiation and Radio Frequency Analysis or Light/Laser Attack.</li></ul><p><strong>Invasive Attack</strong>: open package (the packaging is destroyed, the physical integrity of the chip is modified), direct contact to the chip</p><ul><li>Can be performed with circuit modification and Laser / Focused Ion Beam (FIB).</li></ul><h3>Side Channel Attack with Simple Power Analysis (SPA) and Timing Variation</h3><p>Every embedded system has a variative power consumption, it’s depend on the process inside of it. AND, XOR, OR, multiplication, addition operation have different instantaneous power over time. The CMOS (transistor) inside the chip have a different time to charge and discharge the gate. The behavior make the circuit have different current on every process.</p><p>With the help of data acquisition tools, we can capture the power on every process and then use it to analyze behavior of the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*sAwuLN7az_ZfBxHjSpTcOg.png" /></figure><p>In this post I will give an example to break PIN authentication with Simple Power Analysis and Timing Variation. In this example the PIN authentication program was running on <a href="https://rtfm.newae.com/Capture/ChipWhisperer-Nano/"><strong>Chiwhisperer Nano Board</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-XvbZ7jIJF5TlUo_likY_Q.png" /><figcaption>CW Nano</figcaption></figure><p>The system has 5 digit PIN (consist an alphabet and a number). This is the pseudo code of the program.</p><pre>MAIN FUNCTION<br>...</pre><pre>IF check_PIN(...) == -1<br> AnotherProcess()<br> PRINT(&quot;Failed&quot;)<br>ELSE<br> PRINT(&quot;Access Granted&quot;)</pre><pre>FUNCTION check_PIN (USER_PIN, CORRECT_PIN)<br> FOR i=1 to PIN_LENGTH<br>  IF USER_PIN[i] != CORRECT_PIN[i]<br>   RETURN -1<br> ENDFOR<br> RETURN 0</pre><p>If the user input a wrong PIN, the system will run another process before the system ends. the <strong>AnotherProcess() </strong>is do nothing process with a random time variation on every process. You can input only 1 PIN value in this authentication, of course the the output will be failed. To break the PIN authentication we will use Divide and Conquer technique to get a correct PIN one by one.</p><p>Ok Let’s start the breaking process</p><p>1. I will guest the first PIN digit with ‘x’ as a input and capture the power of the board. The following figure show the power traces of CW Nano Board when running the PIN authentication process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLfE0p3sNrPGSn7qfCueaQ.png" /></figure><p>2. I will use another PIN value to see the differences of power traces. I will use ‘1’, ‘c’, ‘f’, ‘r’, ‘p’ as a first PIN value. The following figure show the result of 5 different input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VfLaWT-GxvUL6G9eAD_0wA.png" /></figure><p>3. Nothing changes with the different output, I will use all possible PIN “abcdefghijklmnopqrstuvwxyz0123456789” to the system and see what happen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T6CTYVfpXKF5SUfq1xg8Bw.png" /></figure><p>The traces is very noisy, but we can see from 36 possible value, only 1 value has different pattern. The input ‘h’ with index 7 has a different pattern among the other.</p><p>This is the following figure after the traces with input ‘h’ is hidden.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fZh6u5X_0fupBWTE4TaLpQ.png" /></figure><p>Wow the 35 input have same pattern, only 1 value has a different pattern. We can make hypothesize that the ‘h’ is the first correct PIN value.</p><p>If you see to the result, only 2 type of traces pattern are exist, the first one is the false pattern, and the second one is a true pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*i5cBAGCoKFZ1TySJ7FTySw.png" /></figure><p>If you look closer to the traces. The true and the false pattern have similar pattern in beginning and in ending.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*47zdB6hjorWKk50Tj1jUAw.png" /></figure><p>We can conclude that the system is doing the same thing in the first, but when the correct PIN is inputted the system execute another process before the same process with the wrong PIN is executed. To see the similarity of the traces I shift the false traces 11 point to the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*bvsZHY37KfztlOEj0PjsaQ.png" /></figure><p>Wow it is very similar, ok Let’s zoom the traces and see the interesting pattern in true trace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMYlkNGS5z2xrBv7btJzHg.png" /></figure><p>Ok we have found the interesting pattern appear in around sample point 20 with the highest peak in point 22.</p><p>4. After we found the correct first PIN value is ‘h’, let’s try to the second PIN digit and try all possibility of alphabet and numeric as like previous step. After that we can see the true correct pin will execute some process like figure bellow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYA5wnfdNLjwF_zk2D_9DA.png" /></figure><p>We can see when the correct PIN is inputted, there is a process with length 11 sample point.</p><p>5. To break all 5 PIN digit, we can analyze the traces with all possibility one by one until we get all the PIN value</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UfOOyA0fvsRa6cYjblSq4Q.png" /></figure><p>Or we can automate the process with this scenario.</p><pre>FUNCTION checkpass(trace, i):<br>    RETURN (trace[22 + 11*i] &gt; 0.45)</pre><pre>MAIN FUNCTION<br>trylist = &quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;<br>password = &quot;&quot;</pre><pre>FOR i=1 to 5<br>    FOR c in trylist:<br>        next_pass = password + c + &quot;\n&quot;<br>        trace = get_traces(next_pass)<br>        IF checkpass(trace, i):<br>            password += c<br>            PRINT(&quot;Success, pass now {}&quot;.format(password))<br>            BREAK</pre><p>We already know that the first highest peak in sample point 22, and the distance between the peak is 11 sample point, we can use threshold value (i.e. : 0.45) to detect if the process is the correct one and then run 180 (36*5) times to guest for 5 PIN digit value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpyurnGEly3Xk3eyOn4nLQ.png" /></figure><p>Huala The attacking process is success. We can break the PIN with 180 times execution. This method is more efficient than the normal brute force. In the normal brute force you have to run 36⁵ (60.466.176) execution until you get the correct PIN value.</p><h3>Conclusion</h3><p>That’s all introduction about Side Channel Attack (SCA), this method is powerful enough to break plain cryptographic algorithm like DES, AES, RSA, and ECC. In the next post I will talk about how to break DES/AES with Non Profiled SCA with <strong>Differential Power Analysis</strong> <strong>(DPA)</strong> and <strong>Correlation Power Analysis</strong> <strong>(CPA)</strong>.</p><blockquote>-THANKYOU-</blockquote><p><strong>Reference:</strong></p><ul><li>“Introduction to Side Channel Attack”, 15th International COSIC Course — Josep Balasch. 2015</li><li><a href="https://github.com/newaetech/chipwhisperer">Chipwhisperer Github</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afa393d457d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptography : Advanced Encryption Standard (AES)]]></title>
            <link>https://kresna-devara.medium.com/cryptography-advanced-encryption-standard-aes-5c09b0da76e4?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c09b0da76e4</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Wed, 30 Sep 2020 14:53:31 GMT</pubDate>
            <atom:updated>2020-09-30T14:54:05.608Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cryptography : Advanced Encryption Standard (AES)</h3><p>Halo, pada post sebelumnya saya telah menjelaskan mengenai <a href="https://medium.com/@kresna.devara/cryptography-data-encryption-standard-des-e23aac8d5896"><strong>Cryptogaphy DES</strong></a>. Pada post kali ini, saya akan menjelaskan mengenai algoritma symmetric lainnya, yaitu: <strong>Advanced Encryption Standard (AES)</strong>. Selain <strong>DES</strong>, algoritma <strong>AES </strong>adalah algoritma yang saat ini masih banyak digunakan dalam berbagai bidang, selain prosesnya yang cepat tingkat keamaan <strong>AES</strong> sangatlah tinggi. Sampai saat ini algoritma ini masih belum berhasil dibobol dengan metode cryptoanalys. Oke langsung saja kita ke pembahasannya.</p><h3>Advanced Encryption Standard (AES)</h3><p><strong>AES </strong>merupakan algoritma cryptography <strong>symmetric </strong>yang sampai saat ini masih digunakan diberbagai macam aplikasi. Algoritma ini telah disahkan sebagai algoritma untuk data encryption standard oleh <a href="https://en.wikipedia.org/wiki/National_Institute_of_Standards_and_Technology"><strong>National Institute of Standards and Technology</strong></a> (<strong>NIST</strong>) pada tahun 2001. Sebenarnya nama original dari <strong>AES </strong>adalah algoritma <strong>Rijndael</strong>, dimana algoritma ini pertama kali dikembangkan oleh <a href="https://en.wikipedia.org/wiki/Vincent_Rijmen">Vincent Rijmen</a> dan <a href="https://en.wikipedia.org/wiki/Joan_Daemen">Joan Daemen</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*HxLqniFQWiZY3zD4gRLzEA.png" /></figure><p>Pada awalnya algoritma Rijandael merupakan hasil kompetisi yang diadakan oleh NIST setelah sebelumnya algoritma DES berhasil dibobol. Selain Rijndael terdapat dua kandidat terkuat lainnya yaitu <a href="https://en.wikipedia.org/wiki/Serpent_(cipher)">Serpent</a> dan juga <a href="https://en.wikipedia.org/wiki/Twofish">Twofish</a>. Namun Rijndael berhasil memenangi score dengan nilai pengujian 86 positif dan 10 negatif, sehingga algoritma Rijandael diresmikan sebagai standar enkripsi dengan nama <strong>AES</strong>.</p><p>Rijndael merupakan algoritma berjenis block cipher dengan jumlah key yang berbeda-beda. Namun untuk <strong>AES</strong> NIST memilih 3 sub bagian dari Rijndael, setiap blok terdiri dari 128 bit input data, dengan 3 jenis ukuran <strong>key </strong>yang berbeda yaitu: <strong>128</strong>, <strong>192 </strong>atau <strong>256 </strong>(bit). Proses <strong>AES </strong>terdiri dari beberapa sub proses. Untuk lebih jelasnya lihatlah gambar berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*pKwpiyrohQMSsfTr8S7XEw.png" /><figcaption>Struktur AES</figcaption></figure><p>Algoritma<strong> encryption </strong>ataupun <strong>decryption </strong>pada<strong> AES </strong>terdiri dari proses <strong>awal </strong>yaitu:<strong> Key Expansion </strong>dan <strong>AddRoundKey, </strong>proses <strong>utama </strong>yaitu:<strong> SubBytes — ShiftRows — MixColumns — AddRoundKey </strong>dan proses<strong> akhir </strong>yaitu: <strong>SubBytes — ShiftRows — AddRoundKey</strong>. Pada proses utama jumlah pengulangan atau <strong>round</strong>, dimana pengulangan yang terjadi bergantung dengan jumlah key yang digunakan</p><pre>128 bit key -&gt; 9  kali<br>192 bit key -&gt; 11 kali<br>256 bit key -&gt; 13 kali</pre><p>Untuk lebih jelasnya mari kita langsung mengerjakan contoh</p><pre><strong>Data yang akan diencrypt</strong>: HELOBUDYSAYAKRES (dalam bentuk ASCII), kita ubah ke bentuk HEX menjadi</pre><pre>Plaintext: 48 45 4c 4f 42 55 44 59 53 41 59 41 4b 52 45 53<br>Key: 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF</pre><h4>Key Expansion/Schedule</h4><p>Sama seperti DES yang memiliki proses <strong>key schedule</strong>, <strong>AES </strong>juga memiliki proses yang disebut <strong>key expansion</strong>. Pada proses ini <strong>key utama</strong> akan diperbanyak menjadi <strong>10/12/14</strong> buah tergantung dari jumlah ukuran key yang digunakan. Pada kali ini kita akan menggunakan key dengan ukuran 16 byte (<strong>128 </strong>bit) sehingga kita akan memiliki <strong>10</strong> buah key berbeda untuk masing-masing <strong>round</strong>nya. Berikut adalah gambaran proses <strong>key expansion </strong>pada AES</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0siwm4dfpxRDYPGLi-bTMQ.png" /><figcaption>Diagram Key Expansion AES</figcaption></figure><p><strong>Pertama </strong>— Kita akan merubah 16 byte <strong>key utama</strong> kedalam bentuk matrix 4x4 seperti berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*bkxFrMH4boBLWY7fYFXijg.png" /></figure><p><strong>Kedua </strong>— Kita akan melakukan proses <strong>RotWord</strong>, dimana pada algoritma <strong>AES</strong> prosesnya adalah “<strong>one byte left circular shift</strong>”, atau menggeser posisi byte ke kiri secara circular. Pada proses pertama, kita akan mengambil kolom terakhir dari matrix <strong>key utama.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*sfJo5duJO_7ETr3xAJZiwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*8USnw9yM-SRTsdCZxKUrmA.png" /></figure><p><strong>Ketiga </strong>— Kita akan melakukan proses <strong>SubWord</strong>. Pada proses ini kita akan petakan setiap byte key dengan menggunakan tabel <strong>S-Box AES</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*zAHQX-DtBv_vkKnM4Ug59A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*aUo881u9lovdtiSD22b2Nw.png" /><figcaption>Tabel S-Box AES</figcaption></figure><p>Pada contoh sebelumnya 4 byte pada kolom terakhir adalah DD, EE, FF, dan CC maka padanan pada <strong>S-Box</strong> adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*7MOirtpro0dPUYAnpZZOsQ.png" /></figure><p>Sehingga kita mendapatkan nilai</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*DR7RXD8xl784n2i8Sa0jpQ.png" /></figure><p><strong>Keempat </strong>— Kita akan melakukan proses <strong>Rcon</strong>, dimana 4 byte hasil <strong>S-Box</strong> akan di <strong>XOR</strong>-kan dengan matrix konstan Rcon</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*rSRFrJsIt2IIVWf9YBL3vA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*G1D-OpUrGxKwB0JWkl6boQ.png" /></figure><p><strong>i</strong> merupakan nomor <strong>round</strong> saat proses dilakukan. Untuk <strong>AES 128 bit</strong> terdapat <strong>10 </strong>jumlah round, sehingga nilai <strong>rci</strong> untuk masing-masing round adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*_xEE4cMSCU6vQmNREs3QFw.png" /></figure><p>Sehingga pada proses <strong>round 1</strong> matrix rcon yang digunakan adalah [01 00 00 00] di <strong>XOR</strong>-kan dengan hasil S-Box sebelumnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*eyzaj6ydPAnZUPGbaPpv2A.png" /></figure><p><strong>Kelima </strong>— Hasil dari proses <strong>Rcon</strong> akan di-<strong>XOR</strong>-kan dengan <strong>key utama</strong> pada kolom ke 0 yaitu [00 11 22 33]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*9uzraUqMQq3IBgb5BYKcOw.png" /></figure><p>Hasil dari XOR pada proses pertama akan dilakukan XOR lagi dengan key utama pada kolom ke 1 yaitu [44 55 66 77] sehingga mendapatkan hasil</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*Tw6AkdX1bS1rvVqFQzoYLg.png" /></figure><p>Proses ini akan berulang hingga kita mendapatkan 4 kolom baru seperti yang telah ditunjukan pada diagram <strong>key xpansion AES</strong>. Sehingga kita akan mendapatkan 16 byte <strong>sub key</strong> untuk <strong>round 1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*Wi9evPMFqiKLtMtBipFxLQ.png" /></figure><p>Kita akan mengulang kelima proses di atas sebanyak 10 kali hingga mendapat <strong>10 sub key</strong> untuk <strong>10 round</strong> pada AES. Hasilnya adalah sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*rc1yQ1LOf-ww8Uu4Id1ViA.png" /></figure><h4>Add Round Key</h4><p>Pada proses ini kita akan melakukan <strong>XOR </strong>antara <strong>plaintext </strong>dengan <strong>key utama</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zNJnlghhQAqhfJaODf3rJg.png" /></figure><h4>Proses Encryption — Sub Bytes</h4><p>Proses selanjutnya adalah <strong>Sub Bytes</strong>. Proses ini sama dengan proses s<strong>ub bytes</strong> pada <strong>key expansions</strong>, dimana hasil dari <strong>add round </strong>key sebelumnya kita petakan ke dalam tabel S-Box AES. Contohnya pada kolom pertama [48 54 6E 7C</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*6Dnt0sHZ5m9d7dEqbv_OZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*lOlozQiWFhij35a1s3aunw.png" /></figure><p>Sehingga untuk keseleruhan proses kita mendapatkan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*EuITELnBztl-HmK_w6vSug.png" /></figure><h4>Proses Encryption — Shift Row</h4><p>Proses selanjutnya adalah <strong>Shift Row</strong>, dimana kita akan melakukan pergeseran baris pada matrix ke sebelah kiri sebanyak:</p><pre>Baris Ke 2 &lt;&lt; 1 kali<br>Baris Ke 3 &lt;&lt; 2 kali<br>Baris Ke 4 &lt;&lt; 3 kali</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*h9O1HjVJR2C6QoGyENTBJw.png" /></figure><h4>Proses Encryption — Mix Column</h4><p>Setelah kita melakukan proses <strong>Shift Row</strong>, selanjutnya kita akan melakukan proses <strong>Mix Column</strong> pada matrix. Proses ini relatif lebih sulit dikarenakan kita akan melakukan perkalian pada <strong>Galois Field</strong> dengan orde GF(2⁸).</p><p>Pertama kita akan melakukan perkalian antara matrix dengan menggunakan Matrix Mix Column</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/277/1*Uh9Xtu206c3Kkoxr_JOOUA.png" /><figcaption>Matrix Mix Column</figcaption></figure><p>Contohnya kita akan melakukan perkalian pada kolom pertama dari input sebelumnya terlebih dahulu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*qAIfgZQNwotnSmvIwT5TLg.png" /></figure><p>Untuk perkalian pertama yaitu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*zG6XMnY0hKDuwgDbWzAPiw.png" /></figure><p>Kita dapat melakukan proses perkalian pada <strong>Galois Field</strong> secara matematis langsung ataupun dengan menggunakan pendekatan algoritma. Pada kali ini saya akan membahas perhitungan secara matematis.</p><p><strong>Pertama </strong>kita konversikan terlebih dahulu bilangan-bilangan Hexadesimal tersebut menjadi bentuk <strong>binernya</strong>, lalu kita <strong>transformasikan </strong>ke dalam bentuk <strong>Polynomialnya</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*oRkd-uA4rlCYN8wXm5-q5Q.png" /></figure><p>Setelah itu kita akan melakukan proses perkalian polynomial seperti biasa</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*rHajVH9sN7ZsfAqVPfWogA.png" /></figure><p>Selanjutnya kita transformasikan lagi ke dalam bentuk biner dan kita konversi kan kembali ke dalam bentuk Hexadesimal. Contoh selanjutnya adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*V8PbZGhpWwqvRfBqJEu3_A.png" /></figure><p>Pada penjumlahan dalam Galois Field, jika terdapat penjumlahan <strong>1+1</strong> maka hasilnya adalah <strong>0</strong>, dimana hal ini serupa dengan operasi <strong>XOR</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CYebtLHnKTraLgbqLJ9ozQ.png" /></figure><p>Sehingga untuk d0 kita mendapatkan hasil</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*CojEvmOcB95ApcXTIvKr7w.png" /></figure><p>Dalam Galois Field dengan orde 2⁸ jika kita mendapatkan hasil polynomial <strong>lebih dari x⁷</strong> kita perlu melakukan pembagian modulus dengan menggunakan <strong>irreducible polynomial</strong> → <strong>x⁸ + x⁴ + x³ + x +1</strong>. Contohnya jika kita memiliki perkalian bilangan berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6-BaEPzf3CjKXXQHmtBFA.png" /></figure><p>dimana pembagian modulusnya adalah sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*FXW4skZCmB9mx-dw3ikI_g.png" /></figure><p>Sehingga hasil akhirnya adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*hf1E-zYGUQtGpMVeRPsJQg.png" /></figure><p>Setelah kita melakukan <strong>mix column</strong> untuk semua kolom pada matrix input, maka kita akan mendapatkan hasil</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*4a8UP5_A_OKiY86T9pUIqA.png" /></figure><h4>Proses Encryption — Add Key</h4><p>Proses selanjutnya adalah melakukan <strong>XOR </strong>antara input hasil <strong>mix column </strong>dengan <strong>sub key</strong> yang telah didapat dari proses <strong>key expansion</strong>. Pada contoh ini adalah <strong>round 1</strong>, sehingga Sub Key yang digunakan adalah yang pertama</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wDqthYwMiCPSugsTmf4eAw.png" /></figure><p>Hasil dari <strong>add key </strong>akan digunakan kembali sebagai input <strong>proses encryption </strong>(sub byte, shift row, mix column, add key) selanjutnya. Seluruh proses akan dilakukan kembali sampai dengan <strong>round 9</strong> . Untuk round ke 10 prosesnya masih sama, namun pada round ini proses <strong>mix column</strong> tidak dilakukan.</p><p>Setelah melakukan seluruh proses sebanyak 10 round, maka hasil <strong>encryption </strong>adalah sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*iYExU6EjTQCbUnE-bDTJXA.png" /></figure><p>Sulit sekali bukan !!! prosesnya terlihat lebih simple dibandingkan DES. Namun ketangguhan AES sangatlah hebat dikarenakan sampai sekarang algoritma ini masih belum berhasil dibobol secara cryptoanalys. Dengan komputer paling canggihpun saat ini AES masih belum mampu dibobol. Namun mungkin dengan berkembangnya teknologi kuantum dan juga super komputer, mungkin kedepannya AES akan berhasil dibobol.</p><p>Untuk lebih jelasnya saya sudah membuat contoh pemograman AES dengan menggunakan pemograman python pada jupyter notebook yang bisa diakses di <a href="https://github.com/kresdev/Crypto/tree/master/AES">Example AES</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWqmdiIEw-8fPuQ7I2lVrQ.png" /><figcaption>Aplikasi AES pada Python Notebook</figcaption></figure><h3>Penutup</h3><p>Sekian dulu penjelasan mengenai algoritma <strong>AES.</strong> Hingga saat ini <strong>AES </strong>masih belum mampu dibobol secara langsung. Namun terdapat metode lain yang disebut <strong>Side Channel Analysis/Attack (SCA)</strong> dimana kita dapat membobol <strong>AES </strong>dari <strong>leakage </strong>yang terjadi pada perangkat yang digunakan, misalnya dengan menggunakan Daya (<strong>Power Measurement</strong>) ataupun <strong>Elektro Magnetik</strong>. Pada post selanjutnya saya akan membahas mengenai metode <strong>Side Channel Attack</strong> untuk melakukan pembobolan pada <strong>AES </strong>dan juga algoritma lainnya.</p><p>Materi terkait lainnya:</p><ul><li><a href="https://medium.com/@kresna.devara/cryptography-apaan-tuh-fe3d7cff1716">Cryptography… Apaan-tuh?</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a">Cryptography Caesar Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10">Cryptography Vigenere Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-data-encryption-standard-des-e23aac8d5896">Cryptography: Data Encryption Standard (DES)</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-advanced-encryption-standard-aes-5c09b0da76e4">Cryptography: Advanced Encryption Standard(AES)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c09b0da76e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptography : Data Encryption Standard (DES)]]></title>
            <link>https://kresna-devara.medium.com/cryptography-data-encryption-standard-des-e23aac8d5896?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e23aac8d5896</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[data-encryption-standard]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Thu, 03 Sep 2020 15:02:17 GMT</pubDate>
            <atom:updated>2020-09-30T14:19:40.326Z</atom:updated>
            <content:encoded><![CDATA[<h3>Cryptography : Data Encryption Standard (DES)</h3><p>Halo, pada post sebelumnya saya telah menjelaskan mengenai <a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10"><strong>Cryptogaphy Vigenere Cipher</strong></a>. Pada post kali ini, saya akan menjelaskan mengenai algoritma symmetric lainnya, yaitu: <strong>Data Encryption Standard (DES)</strong>. <strong>DES </strong>mungkin bisa dibilang salah satu algoritma pertama yang digunakan untuk produk-produk komersial, dimana beberapa cryptography sebelumnya lebih banyak digunakan pada kepentingan militer. Oke langsung saja kita ke pembahasannya.</p><h3>Data Encryption Standard (DES)</h3><p><strong>DES </strong>adalah salah satu jenis algoritma cryptography <strong>symmetric </strong>yang cukup populer sampai saat ini. Algoritma ini pertama kali dikenalkan oleh <a href="https://en.wikipedia.org/wiki/Horst_Feistel"><strong>Horst Feistel</strong></a> dari <strong>IBM </strong>pada sekitar tahun 1970 dan telah disetujui oleh <strong>National Bereau of Standard (NBS)</strong> setelah penilain ketangguhannya oleh N<strong>ational Security Agency (NSA)</strong> Amerika Serikat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*XhBuBRGMriOAAIXrhcT-VA.png" /></figure><p><strong>DES </strong>merupakan algoritma bertipe <strong>block cipher, </strong>dimana pengoperasiannya berjalan pada ukuran blok 64 bit <strong>plaintext </strong>untuk menghasilkan 64 bit<strong> ciphertext</strong> dengan menggunakan 64 bit <strong>external key </strong>serta prosesnya yang dilakukan sebanyak <strong>16 round</strong>, dimana setiap round memiliki <strong>sub key</strong> yang berbeda-beda sebanyak 54 bit saja (8 Least Significat Bit hanya untuk checking parity). Karena hal itulah timbul kecurigaan bahwa algoritma ini dapat dibobol melalui “back door” dari design pertamanya, sehingga terjadi pembaharuan oleh <strong>NSA</strong>.</p><p>Dikarenakan tipe algoritmanya berupa <strong>block cipher</strong>, pada informasi dengan panjang lebih dari 64 bit, informasi tersebut akan dipecah menjadi beberapa <strong>block plaintext </strong>dan akan dilakukan proses penggabungan. Pada pembahasan kali ini kita akan membahas terlebih dahulu cara kerja dasar algoritma <strong>DES</strong> pada <strong>plaintext </strong>64 bit. Untuk lebih jelasnya mari kita lihat blok diagram DES berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*fJzTiHhpFWe2FspHCIXk6g.png" /><figcaption>Struktur DES</figcaption></figure><p>Algoritma<strong> encryption </strong>ataupun <strong>decryption </strong>pada<strong> DES </strong>terdiri dari proses <strong>Initial Permutation </strong>— <strong>Round </strong>— <strong>Final Permutation</strong>. Dimana masing-masing <strong>round </strong>akan menggunakan <strong>sub keys</strong> yang berbeda-beda. Proses <strong>Key schedule</strong> dilakukan untuk menghasilkan <strong>sub keys</strong> pada masing-masing <strong>round. </strong>Untuk lebih jelasnya mari kita langsung masuk ke contoh kasus.</p><p>Jika kita memiliki</p><pre>Data yang akan diencrypt: HELOBUDY (dalam bentuk ASCII), kita ubah ke bentuk HEX menjadi</pre><pre>Plaintext: 48 45 4c 4f 42 55 44 59<br>Key: 11 22 33 44 55 66 77 88</pre><h4>Key Schedule</h4><p>Pertama-tama kita akan melakukan proses <strong>Key Schedule.</strong> Kita perlu merubah <strong>Key </strong>yang ada menjadi dalam bentuk biner:</p><pre>Key: <br>00010001 00100010 00110011 01000100 01010101 01100110 01110111 10001000</pre><p>Key akan dimelalui proses <strong>Permuted Choice 1 (PC-1)—Cyclic Shift — Permuted Choice 2 (PC-2)</strong> untuk mendapatkan <strong>sub key</strong> pada setiap round.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*PkrUSET3cvLP4Ok7JlmoFw.png" /><figcaption>Proses Key Schedule</figcaption></figure><p>Selanjutnya kita akan memberikan index dari masing-masing <strong>key </strong>yang ada seperti berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*N1BsXy2_FQswp0TBXjMUig.png" /><figcaption>Key Index</figcaption></figure><p>Setelah itu kita akan melakukan proses <strong>Permuted Choice 1</strong> <strong>(PC-1)</strong>. dengan menggunakan tabel referensi sebagai berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*Sd2xTh6Y_WyV1yJq3ilxFw.png" /><figcaption>Tabel PC-1 DES</figcaption></figure><p>Pada PC-1 ini kita akan membagi bit-bit menjadi dua bagian: “Left (<strong>C0</strong>)” dan “Right (<strong>D0</strong>)”. Contohnya untuk baris pertama pada <strong>C0 </strong>dengan urutan 57, 49, 41, 33, 25, 17, dan 9. Mari kita lihat padanan Tabel PC-1 dengan <strong>key index</strong> sebelumnya:</p><pre>57 -&gt; 1<br>49 -&gt; 0<br>41 -&gt; 0<br>33 -&gt; 0<br>25 -&gt; 0<br>17 -&gt; 0<br>9  -&gt; 0</pre><p>Sehingga hasilnya akan seperti berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*hPXMIuCMT7yTdcMOfogkwQ.png" /><figcaption>Hasil PC-1</figcaption></figure><p><strong>*Ingat karena kita tidak menggunakan LSB pada masing-masing Byte Key maka pada index (8, 16, 24, 32, 40, 48, 56, 64) nilainya tidak digunakan.</strong></p><p>proses selanjutnya adalah <strong>Cyclic Shift</strong>. Yaitu dengan melakukan pergeseran pada masing-masing <strong>C0 </strong>dan juga <strong>D0</strong>. Pada setiap roundnya <strong>Cyclic Shift</strong> memiliki jumlah pergeseran yang berbeda-beda tergantung dari tabel referensi sebagai berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*yCc5vhW7qmvHjEE1zpFCjg.png" /></figure><p>Misalnya pada Round-1 kita akan melakukan pergeseran <strong>C0 </strong>dan <strong>D0 </strong>sebanyak 1 kali ke sebelah kiri sehingga menghasilkan <strong>C1 </strong>dan <strong>D1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*jGhT7AldNC8nyNDpFEY-6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*m498RyeHAfivpdgeTbjpWQ.png" /></figure><p>Setelah itu kita akan menggunakan <strong>C1 </strong>dan <strong>D1 </strong>untuk <strong>sub key</strong> pada <strong>round-1</strong> dengan melakukan proses <strong>Permuted Choice</strong> (<strong>PC-2</strong>) dan menjadikan jumlah <strong>output sub key</strong> sebanyak 48 bit. Sama seperti pada <strong>PC-1</strong> kita akan menggunakan tabel referensi, namun tabel yang digunakan adalah tabel <strong>PC-2</strong> berikut:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*dovB3UGoVDmg9lqJaQqtCQ.png" /><figcaption>Tabel PC-2 DES</figcaption></figure><p>Sehingga didapatkan hasil seperti berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*u_wVaJdh6zy5LD9IcZsa8Q.png" /><figcaption>Hasil PC-2</figcaption></figure><p>Hasil dari PC-2 lah yang akan digunakan sebagai <strong>sub key</strong> untuk <strong>round-1.</strong> Untuk mendapatkan sub key round-2 kita akan menggunakan <strong>C1 </strong>dan <strong>D1 </strong>untuk menghasilkan <strong>C2 </strong>dan <strong>D2 </strong>pada proses <strong>Cycle Shift</strong>, dilanjutkan dengan proses<strong> PC-2.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*JmZBXboY1oyDpK6raqae6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*AU9m_POluUK4qD5-48gPoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*C8pVFw33i-lj2uU3bJE3bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*W6jyP0a7mz3pVOT0i_Gsgg.png" /></figure><p>Setelah mengulang proses tersebut sampai dengan 16 kali, kita akan mendapatkan <strong>48 bit sub keys</strong> untuk masing-masing <strong>round </strong>pada proses <strong>DES</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*2Z9jOWDLT9PZH-84omWu2g.png" /></figure><h4>Initial Permutation</h4><p>Setelah proses <strong>Key Schedule</strong> selesai, sebelum masuk pada proses <strong>encryption </strong>pada <strong>DES</strong>, kita perlu melakukan proses yang disebut <strong>Initial Permutation (IP</strong>). Pada proses ini <strong>plaintext</strong> akan dilakukan permutasi dengan tabel <strong>IP</strong>. Pertama-tama kita perlu mengkonversikan data <strong>plaintext </strong>ke dalam bentuk <strong>HEX</strong>, kita perlu mengkonversikanya lagi juga ke dalam bentuk biner serta memberikan index seperti pada proses sebelumnya:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*Qdi9Qv-NC3OW3sSLsbWtuA.png" /></figure><p>Selanjutnya kita akan memetakan <strong>plaintext </strong>dengan menggunakan tabel referensi <strong>IP </strong>yang telah disediakan oleh <strong>DES</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*o-vLcLlaUYq4ucJcsevhpw.png" /><figcaption>Tabel IP DES</figcaption></figure><p>Sehingga kita akan mendapatkan hasil sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*9RBSCiqcIQOADsVc-fHXCA.png" /></figure><p>Dari data tersebut kita akan kembali memisahkannya menjadi dua bagian 32 bit pertama kita sebut “Left (<strong>L0</strong>)” dan 32 bit kedua kita sebut “Right (<strong>R0</strong>)”.</p><h4>Proses DES: Feistel Network</h4><p>Setelah kita melakukan proses <strong>IP </strong>pada <strong>plaintext </strong>yang akan digunakan. Selanjutnya kita akan mulai melakukan proses <strong>encryption</strong>. Pada proses ini kita akan menggunakan prinsip dari <strong>Feistel Network</strong> sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*NUeJAScNyC8g9-HUR8phkA.png" /><figcaption>Feistel Network</figcaption></figure><p>Untuk lebih jelasnya mari kita lanjutkan proses pada sub sebelumnya. Pertama-tama kita akan menggunakan nilai <strong>R0 </strong>untuk menjadikannya nilai <strong>L1</strong> selanjutnya sekaligus memasukannya dalam suatu blok fungsi (f).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*A904xYYSj_bhhS1cprSE5Q.png" /></figure><p>Isi dari blok fungsi (f) tersebut adalah <strong>ekspansi</strong>, operasi <strong>XOR </strong>dengan <strong>sub key</strong>, pemetaan dengan menggunakan <strong>S-Boxes</strong>, dan <strong>permutasi</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*dJeYKQBB5SCpwUIVqVewfA.png" /><figcaption>Blok (f) DES</figcaption></figure><p>Pertama-tama nilai <strong>R0 </strong>sebanyak 32 bit akan kita berikan masing-masing index seperti pada proses-proses sebelumnya. Setelahnya kita akan melakukan <strong>ekspansi </strong>bit menjadi 48 bit menggunakan tabel referensi sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*1Ewtg1G1bkpsJHhbybPW6w.png" /><figcaption>Tabel Ekspansi DES</figcaption></figure><p>Sehingga kita akan mendapat 48 bit baru</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*by5W4GaB4lc2iIwnd2ufmg.png" /></figure><p>Selanjutnya 48 bit hasil <strong>ekspansi </strong>akan kita <strong>XOR </strong>dengan menggunakan <strong>Sub Key-1</strong> yang telah kita dapat pada proses <strong>Key Shedule </strong>sebelumnya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/1*NkGf_aTEEycrDnL3oYj22w.png" /></figure><p>Setelah melalui proses <strong>XOR</strong>, kita akan membagi hasilnya menjadi 8 bagian (per 6 bit) untuk kita petakan menggunakan S BOX DES. Sehingga 6 bit input hanya menjadi output 4 bit saja.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*k7pgYIioOEZKrf12aP3N4A.png" /></figure><p>Kita akan melihat <strong>baris </strong>dan <strong>kolom </strong>pada Tabel S BOX untuk mendapatkan <strong>output </strong>bitnya. Contohnya pada 6 bit pertama <strong>011000</strong>. Untuk membaca baris kita melihat <strong>LSB </strong>dan <strong>MSB</strong>nya, pada kasus ini nilainya adalah “0” dan “0” sehingga <strong>baris</strong>nya adalah 0. Untuk membaca <strong>kolom </strong>kita akan melihat bit sisanya, dimana nilainya adalah <strong>1100 </strong>sehingga jika kita konversikan ke desimal nilainya sama dengan 12. hasil output S BOX pada baris 0 dan kolom 12 adalah “5” atau jika kita konversi ke biner adalah <strong>0101</strong>. Kita akan melakukan proses ini sampai dengan 8 kali S BOX (Terdapat 8 jenis tabel SBOX yang berbeda).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*yXhpC1wL3m0DCESK8sLSBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*3nB3RHGevTVazsS0LfbFZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*Z_EVrwkOw4AoTBjR6l3DLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*efptidzqcvA4y5Vrb6d1wQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*az8b6-yaIelrgMv-niPsTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*VaeYBBtqu4HRQgDKbDbIAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*tZbNDNhbnOBPWsbWLkF0dQ.png" /></figure><p>Sehingga hasil dari 8 S BOX adalah sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*THoXZpzBLSw3Smv4keUgdQ.png" /></figure><p>Selanjutnya hasil yang didapatkan akan dimasukan lagi ke dalam permutasi berdasarkan tabel berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*0ucCqyLCP5MhtgJtjqllwQ.png" /></figure><p>Sehingga kita akan mendapatkan 32 bit baru hasil permutasi yaitu</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*iWLBrW2VzPV9HTOIieOZdg.png" /></figure><p>Nilai <strong>R0 </strong>yang telah masuk ke dalam blok function (f) akan dilakukan <strong>XOR </strong>dengan <strong>L0 </strong>sebelumnya sehingga menjadi nilai <strong>R1 </strong>yang baru.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*PzlyJ2DpRUPxJLt5FhfL8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*WZU32C-J9cAIR8w67KYubw.png" /></figure><p>Kita akan menggunakan nilai <strong>L1 </strong>dan <strong>R1 </strong>untuk menghasilkan <strong>L2 </strong>dan <strong>R2 </strong>hingga seterusnya<strong> </strong>sebanyak <strong>16 round</strong> hingga menghasilkan <strong>L16 </strong>dan <strong>R16.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*TanabGl9-eEt9Z8uD4nx1A.png" /></figure><h4>Final Permutation</h4><p>Setelah kita mendapatkan <strong>L16 </strong>dan juga <strong>R16</strong>, kita akan menggunakan data tersebut untuk melakukan <strong>Final Permutation (FP)</strong> dengan menggunakan tabel referensi sebagai berikut</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*47U_QaYxWcuk85216okEww.png" /></figure><p>Sehingga kita akan mendapatkan hasil</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*lQx6xQwy_TRTjoaSCZUi5w.png" /></figure><p>Data inilah hasil dari encryption dengan menggunakan algoritma <strong>DES</strong>. Jika kita rangkum hasilnya adalah seperti berikut ini</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*1cMcx9kbgAg_tSV7GsCUbQ.png" /></figure><p>Atau jika kita lihat dalam bentuk HEX seperti diawal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*Vjgj5DaBNyrAgnv_FVl6eQ.png" /></figure><p>Sulit sekali bukan !!!! Bayangkan bagaimana bisa membobol algoritma serumit ini. Jika kita melakukan <strong>Brute Force</strong>pun kita memiliki kemungkinan key sebanyak 2⁶⁴ = <strong>18.446.744.073.709.551.616</strong> !!!!! Untuk melakukannya dengan cara dan komputer biasa hampir sulit sekali dilakukan.</p><p>Sayangnya pada tahun 1997 terdapat pengumuman bahwa <strong>DES</strong> berhasil dibobol, dan pada dua tahun setelahnya metode “Deep Crack” berhasil membobol DES hanya dalam waktu 22 jam 15 menit saja !!! Dikarenakan hal inilah dibutuhkan algoritma yang lebih kuat sehingga penggunaan <strong>DES </strong>diperbaharui menjadi <strong>Triple DES (3DES)</strong>. Selain itu muncul algoritma baru yang lebih cepat namun lebih tangguh yaitu <strong>Advance Encryption Standard (AES).</strong></p><p>Untuk lebih jelasnya saya sudah membuat contoh penggunaan <strong>DES </strong>dengan menggunakan pemograman Python pada jupyter notebook yang bisa diakses di Example <a href="https://github.com/kresdev/Crypto/blob/master/DES/1.%20DES.ipynb">DES</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mv_tU-kON9ZPwz2k6-y1sg.png" /><figcaption>Aplikasi DES pada Python Notebook</figcaption></figure><h3>Penutup</h3><p>Sekian dulu penjelasan mengenai algoritma <strong>DES</strong>. Algoritma ini sangat sulit sekali dibobol tanpa menggunakan komputer berspesifikasi tinggi. Namun terdapat metode lain yang disebut <strong>Side Channel Analysis/Attack (SCA)</strong> dimana kita dapat membobol <strong>DES </strong>dari <strong>leakage </strong>yang terjadi pada perangkat yang digunakan, misalnya dengan menggunakan Daya (<strong>Power Measurement</strong>) ataupun <strong>Elektro Magnetik</strong>. Cara ini sangat ampuh, jauh lebih cepat dan efisien dibandingkan kita melakukan Brute Force !!! Pada kesempatan lainnya saya akan membahas mengenai metode <strong>Side Channel Attack</strong> untuk melakukan pembobolan pada <strong>DES</strong> dan juga algoritma lainnya.</p><p>Materi terkait lainnya:</p><ul><li><a href="https://medium.com/@kresna.devara/cryptography-apaan-tuh-fe3d7cff1716">Cryptography… Apaan-tuh?</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a">Cryptography Caesar Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10">Cryptography Vigenere Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-data-encryption-standard-des-e23aac8d5896">Cryptography: Data Encryption Standard (DES)</a></li></ul><blockquote><em>-Terimakasih-</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e23aac8d5896" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptography Vigenere Cipher]]></title>
            <link>https://kresna-devara.medium.com/cryptography-vigenere-cipher-5575752f4d10?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5575752f4d10</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[vigenere]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 14:25:02 GMT</pubDate>
            <atom:updated>2020-09-30T14:17:01.453Z</atom:updated>
            <content:encoded><![CDATA[<p>Halo, setelah sebelumnya saya membahas mengenai cryptography <a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a">Caesar Cipher</a>. Pada kesempatan kali ini saya akan membahas algoritma lainnya yaitu <strong>Vignere Cipher</strong>. Algoritma ini prinsip dasarnya sama dengan <strong>Caesar Cipher</strong>, yaitu melakukan subtitusi dan pergeseran pada <strong>plaintext</strong>, namun kemungkinan <strong>key</strong> yang digunakan bisa lebih banyak. Mari kita langsung ke pembahasan.</p><h3>Vigenere Cipher</h3><p><strong>Vigenere Cipher</strong> merupakan jenis algoritma cryptography dengan melakukan perubahan informasi melalui subtitusi (pergeseran) dengan menggunakan <strong>key </strong>berupa deretan kata.</p><p>Algoritma ini pertama kali dikenalkan oleh <a href="https://en.wikipedia.org/wiki/Giovan_Battista_Bellaso">Giovan Battista Bellaso</a> pada abad ke 16 dengan sebutan <strong>Autokey Cipher</strong>. Algoritma ini sangatlah tangguh terhadap pembobolan sampai abad ke 19. Sampai dengan <a href="https://en.wikipedia.org/wiki/Friedrich_Kasiski">Friedrich Kasiski</a> memperkenalkan metode miliknya untuk melakukan <strong>dechipering Vigenere Cipher </strong>yang disebut<strong> Kasiski Algorithm. </strong>Pada abad ke 19 juga seorang ilmuan bernama <a href="https://en.wikipedia.org/wiki/Blaise_de_Vigen%C3%A8re">Blaise de Vigenère</a> memperbaharui algoritma <strong>Autokey Cipher</strong>, dan telah terjadi kesalah pahaman tentang “first inventor” dari algoritma ini, sehingga namanya-lah yang digunakan sebagai nama dari algoritma <strong>Vigenere Cipher</strong> hingga sampai saat ini.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*5qkHsgl_SFpn5GQb8-0t4g.png" /></figure><p>Pada dasarnya algoritma ini hampir sama dengan algoritma <strong>Caesar Cipher </strong>hanya saja <strong>key </strong>yang digunakan tidak menggunakan satu nilai, melainkan deretan kata yang telah dimetakan kedalam angka numerik. Formula yang digunakan untuk melakukan <strong>encryption </strong>dan <strong>decryption</strong>nya<strong> </strong>pun serupa yaitu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*9eyf93ZAeqgdBVytN6IG8A.png" /></figure><ul><li>E(x) adalah hasil <strong>encryption</strong>, dimana x adalah dari huruf original atau <strong>plaintext</strong>.</li><li>D(x) adalah hasil <strong>decryption</strong>, dimana x adalah dari huruf yang telah terdecrypt atau <strong>ciphertext</strong>.</li><li>k adalah nilai atau <strong>key</strong> yang digunakan untuk menggeser huruf. Pada <strong>Vigenere Cipher</strong> i menunjukan huruf ke- yang dilakukan <strong>encryption</strong></li><li>Mod 26 masih digunakan dikarenakan untuk membuat kata kita masih menggunakan huruf alfabet, sehingga ketika nilai operasinya lebih atau kurang dari 26 maka kita akan tetap dapat melakukan pemetaannya.</li><li>Kita ingin memastikan bahwa hasil dari encryption masih berada dalam rentang dari [0, ukuran_alfabet-1], sehingga kita gunakanlah mod26.</li></ul><h3>Contoh Kasus:</h3><p>Kita akan melakukan <strong>encryption </strong>pada kalimat “HALO BUDYMAN” dimana <strong>key </strong>yang kita gunakan adalah kata “RAHASIA”. Maka untuk menghasilkan <strong>ciphertext </strong>hal yang kita lakukan adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y8ZZpJ6oPM0FpMevzQLZPA.png" /></figure><p>Sedangkan untuk melakukan <strong>decrpytion </strong>kita hanya akan melakukan hal yang sebaliknya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gFRFQpy8HbNUpPgLTCJdLw.png" /></figure><p>Mudah sekali bukan !!! Proses yang dilakukan sama persis dengan yang dilakukan <strong>Caesar Cipher </strong>hanya saja <strong>key</strong> yang digunakan akan lebih beragam tergantung kata yang kita gunakan sebagai <strong>key</strong>nya. Karena hal inilah algoritma <strong>Vigenere Cipher</strong> cukup lama dapat dibobol hingga metode kasiski ditemukan.</p><p>Untuk lebih jelasnya saya sudah membuat contoh penggunaan <strong>Vigenere Cipher </strong>dengan menggunakan pemograman Python pada jupyter notebook yang bisa diakses di Example <a href="https://github.com/kresdev/Crypto/blob/master/Vigenere%20Cipher/1%20-%20Vigenere%20Cipher.ipynb">Vigenere Cipher</a>. <strong>Pada contoh di jupyter notebook, list alphabet ditambahkan “spasi” yang berada pada index 0, sehingga totalnya list alphabet berubah menjadi 27.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*LuEAmLP7rmAY7xXxrGydFA.png" /><figcaption>Aplikasi Vigenere Cipher pada Python Notebook</figcaption></figure><h3>Cracking Vigenere Cipher</h3><p>Melakukan pembobolan pada <strong>Vigenere Cipher </strong>jauh lebih sulit dibandingkan dengan melakukannya pada <strong>Caesar Cipher</strong>. Dikarenakan jumlah kemungkinan key nya sangatlah besar yaitu <strong>26^(panjang key)</strong>. Terdapat dua cara untuk melakukan pembobolan pada algoritma ini yaitu:</p><ul><li><strong>Dictionary Attack</strong>, kita bisa menggunakan kumpulan dari kata pada suatu database dan melakukan <strong>Brute Force Attack</strong>.</li><li>Menggunakan<strong> Kasiski Algorithm.</strong></li></ul><h4>Kasiski Algorithm</h4><p>Algoritma ini dibuat oleh <strong>Friedrich Kasiski</strong> pada tahun 1863 dan dikembangkan juga oleh <strong>Charles Babbage</strong>. Pada dasarnya jika kita mengetahui panjang dari <strong>key </strong>yang digunakan, kita bisa melakukan <strong>analisa frekuensi </strong>untuk melakukan <strong>decryption </strong>pada <strong>ciphertext </strong>yang kita miliki. Informasi leaking sangat diperlukan untuk dapat melakukan pembobolan dengan menggunakan algoritma ini. Tahap-tahapannya adalah sebagai berikut</p><ol><li>Kita harus menemukan kata yang berulang (<strong>repeated substrings</strong>) pada <strong>ciphertext </strong>(minimal 3 huruf berurutan berulang).</li><li>Mencari jarak antara repeated subtrings<strong> </strong>dan menemukan <strong>faktor </strong>untuk valuenya.</li><li>Kita gunakan <strong>analisa frekuensi</strong> untuk menemukan kata yang digunakan untuk <strong>key.</strong></li><li>Melakukan <strong>Brute Force</strong> dengan menggunakan <strong>sub keys</strong> yang memungkinkan.</li></ol><h4>Contoh kasus:</h4><p>Misalnya terdapat suatu <strong>ciphertext</strong></p><pre>PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU</pre><h4><strong>1. Mencari Kata Berulang (Repeated Substrings)</strong></h4><p>dari ciphertext tersebut kita dapatkan tiga jenis kata berulang yaitu: <strong>VRA</strong>, <strong>AZU</strong>, dan <strong>YBN</strong></p><pre>PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIM<a href="https://medium.com/"><strong><em>VRA</em></strong></a>GVOHT<a href="https://medium.com/"><strong><em>VRA</em></strong></a>UCTKSGDDWUOXITLAZUVAV<a href="https://medium.com/"><strong><em>VRA</em></strong></a>ZCVKBQPIWPOU</pre><pre>PPQCAXQVEKGYBNKM<a href="https://medium.com/"><strong><em>AZU</em></strong></a>YBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITL<a href="https://medium.com/"><strong><em>AZU</em></strong></a>VAVVRAZCVKBQPIWPOU</pre><pre>PPQCAXQVEKG<a href="https://medium.com/"><strong><em>YBN</em></strong></a>KMAZU<a href="https://medium.com/"><strong><em>YBN</em></strong></a>GBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU</pre><p>Setelah menemukan kata yang berulang, kita hitung jarak diantaranya:</p><ul><li>Antara kata pertama dan kedua pada <strong>VRA </strong>terdapat 8 huruf.</li><li>Antara kata kedua dan ketiga pada <strong>VRA </strong>terdapat 24 huruf.</li><li>Antara kata pertama dan ketiga pada <strong>VRA </strong>terdapat 32 huruf.</li><li>Antara kata pertama dan kedua pada <strong>AZU </strong>terdapat 48 huruf.</li><li>Antara kata pertama dan kedua pada <strong>YBN </strong>terdapat 8 huruf.</li></ul><h4>2. Mencari Faktor dari Kata Berulang</h4><p>Jarak antara kata berulang pada kalimat di atas adalah 8, 8, 24, 32, dan 48. Faktor-faktornya adalah</p><pre>8 : 2, 4, dan 8.</pre><pre>24 : 2, 4, 6, 8, 12, dan 24.</pre><pre>32 : 2, 4, 8, 16, dan 32.</pre><pre>48 : 2, 4, 6, 8, 12, 24, dan 48.</pre><p>Jika kita hitung jumlah dari setiap faktornya:</p><pre>2 sebanyak 4 buah.</pre><pre>4 sebanyak 4 buah.</pre><pre>6 sebanyak 2 buah.</pre><pre>8 sebanyak 4 buah.</pre><pre>12 sebanyak 2 buah.</pre><pre>16 sebanyak 1 buah.</pre><pre>24 sebanyak 2 buah.</pre><pre>32 sebanyak 1 buah.</pre><pre>48 sebanyak 1 buah.</pre><p>Faktor yang memiliki nilai terbanyak kemungkinan besar adalah panjang dari <strong>key Vigenere Cipher</strong>. Dari contoh diatas faktor dengan jumlah terbanyak adalah 2, 4, dan 8.</p><h4>3. Melakukan Analisa Frekuensi</h4><p>Jika kita mengasumsikan panjang <strong>key</strong>nya adalah 4. Kita akan memetakan kata dengan jarak 4 kata</p><pre>Setiap 4 kata yang dimulai dari huruf pertama: <a href="https://medium.com/"><strong>P</strong></a>PQC<a href="https://medium.com/"><strong>A</strong></a>XQV<a href="https://medium.com/"><strong>E</strong></a>KGY<a href="https://medium.com/"><strong>B</strong></a>NKM<a href="https://medium.com/"><strong>A</strong></a>ZUY<a href="https://medium.com/"><strong>B</strong></a>NGB<a href="https://medium.com/"><strong>A</strong></a>LJO<a href="https://medium.com/"><strong>N</strong></a>ITS<a href="https://medium.com/"><strong>Z</strong></a>MJY<a href="https://medium.com/"><strong>I</strong></a>MVR<a href="https://medium.com/"><strong>A</strong></a>GVO<a href="https://medium.com/"><strong>H</strong></a>TVR<a href="https://medium.com/"><strong>A</strong></a>UCT<a href="https://medium.com/"><strong>K</strong></a>SGD<a href="https://medium.com/"><strong>D</strong></a>WUO<a href="https://medium.com/"><strong>X</strong></a>ITL<a href="https://medium.com/"><strong>A</strong></a>ZUV<a href="https://medium.com/"><strong>A</strong></a>VVR<a href="https://medium.com/"><strong>A</strong></a>ZCV<a href="https://medium.com/"><strong>K</strong></a>BQP<a href="https://medium.com/"><strong>I</strong></a>WPO<a href="https://medium.com/"><strong>U</strong></a></pre><pre>Setiap 4 kata yang dimulai dari huruf kedua: P<a href="https://medium.com/"><strong>P</strong></a>QCA<a href="https://medium.com/"><strong>X</strong></a>QVE<a href="https://medium.com/"><strong>K</strong></a>GYB<a href="https://medium.com/"><strong>N</strong></a>KMA<a href="https://medium.com/"><strong>Z</strong></a>UYB<a href="https://medium.com/"><strong>N</strong></a>GBA<a href="https://medium.com/"><strong>L</strong></a>JON<a href="https://medium.com/"><strong>I</strong></a>TSZ<a href="https://medium.com/"><strong>M</strong></a>JYI<a href="https://medium.com/"><strong>M</strong></a>VRA<a href="https://medium.com/"><strong>G</strong></a>VOH<a href="https://medium.com/"><strong>T</strong></a>VRA<a href="https://medium.com/"><strong>U</strong></a>CTK<a href="https://medium.com/"><strong>S</strong></a>GDD<a href="https://medium.com/"><strong>W</strong></a>UOX<a href="https://medium.com/"><strong>I</strong></a>TLA<a href="https://medium.com/"><strong>Z</strong></a>UVA<a href="https://medium.com/"><strong>V</strong></a>VRA<a href="https://medium.com/"><strong>Z</strong></a>CVK<a href="https://medium.com/"><strong>B</strong></a>QPI<a href="https://medium.com/"><strong>W</strong></a>POU</pre><pre>Setiap 4 kata yang dimulai dari huruf ketiga: PP<a href="https://medium.com/"><strong>Q</strong></a>CAX<a href="https://medium.com/"><strong>Q</strong></a>VEK<a href="https://medium.com/"><strong>G</strong></a>YBN<a href="https://medium.com/"><strong>K</strong></a>MAZ<a href="https://medium.com/"><strong>U</strong></a>YBN<a href="https://medium.com/"><strong>G</strong></a>BAL<a href="https://medium.com/"><strong>J</strong></a>ONI<a href="https://medium.com/"><strong>T</strong></a>SZM<a href="https://medium.com/"><strong>J</strong></a>YIM<a href="https://medium.com/"><strong>V</strong></a>RAG<a href="https://medium.com/"><strong>V</strong></a>OHT<a href="https://medium.com/"><strong>V</strong></a>RAU<a href="https://medium.com/"><strong>C</strong></a>TKS<a href="https://medium.com/"><strong>G</strong></a>DDW<a href="https://medium.com/"><strong>U</strong></a>OXI<a href="https://medium.com/"><strong>T</strong></a>LAZ<a href="https://medium.com/"><strong>U</strong></a>VAV<a href="https://medium.com/"><strong>V</strong></a>RAZ<a href="https://medium.com/"><strong>C</strong></a>VKB<a href="https://medium.com/"><strong>Q</strong></a>PIW<a href="https://medium.com/"><strong>P</strong></a>OU</pre><pre>Setiap 4 kata yang dimulai dari huruf keempat: PPQ<a href="https://medium.com/"><strong>C</strong></a>AXQ<a href="https://medium.com/"><strong>V</strong></a>EKG<a href="https://medium.com/"><strong>Y</strong></a>BNK<a href="https://medium.com/"><strong>M</strong></a>AZU<a href="https://medium.com/"><strong>Y</strong></a>BNG<a href="https://medium.com/"><strong>B</strong></a>ALJ<a href="https://medium.com/"><strong>O</strong></a>NIT<a href="https://medium.com/"><strong>S</strong></a>ZMJ<a href="https://medium.com/"><strong>Y</strong></a>IMV<a href="https://medium.com/"><strong>R</strong></a>AGV<a href="https://medium.com/"><strong>O</strong></a>HTV<a href="https://medium.com/"><strong>R</strong></a>AUC<a href="https://medium.com/"><strong>T</strong></a>KSG<a href="https://medium.com/"><strong>D</strong></a>DWU<a href="https://medium.com/"><strong>O</strong></a>XIT<a href="https://medium.com/"><strong>L</strong></a>AZU<a href="https://medium.com/"><strong>V</strong></a>AVV<a href="https://medium.com/"><strong>R</strong></a>AZC<a href="https://medium.com/"><strong>V</strong></a>KBQ<a href="https://medium.com/"><strong>P</strong></a>IWP<a href="https://medium.com/"><strong>O</strong></a>U</pre><p>Ketika digambungkan maka kata-katanya menjadi:</p><ul><li>PAEBABANZIAHAKDXAAAKIU (gabungan dari 4 kata huruf pertama)</li><li>PXKNZNLIMMGTUSWIZVZBW (gabungan dari 4 kata huruf kedua)</li><li>QQGKUGJTJVVVCGUTUVCQP (gabungan dari 4 kata huruf ketiga)</li><li>CVYMYBOSYRORTDOLVRVPO (gabungan dari 4 kata huruf keempat)</li></ul><p>Pada dasarnya <strong>Vigenere Cipher</strong> sama dengan <strong>Caesar Cipher</strong>, hanya saja <strong>Vigenere Cipher</strong> menggunakan <strong>multiple sub keys</strong>. Sehingga untuk melakukan pembobolannya kita bisa melakukan <strong>decryption</strong> pada gabungan-gabungan kata di atas dengan key dari A hingga Z.</p><p>Kita ambil contoh untuk melakukan <strong>decryption</strong> pada gabungan kata PAEBABANZIAHAKDXAAAKIU. Kita akan melakukan <strong>decryption </strong>dengan menggunakan <strong>sub keys</strong> A — Z. Dan melakukan analisa frekuensi berdasarkan <strong>English Frequency Match Score.</strong></p><p><strong>English Frequency Match Score </strong>yang digunakan yaitu dengan melihat berapa score huruf paling sering muncul dari hasil <strong>decryption </strong>pada setiap <strong>key </strong>dengan merujuk berapa banyak 6 huruf yang paling sering muncul dalam bahasa inggris (ETAOIN) dan 6 huruf yang paling tidak sering muncul dalam bahasa inggris (VKJXQZ).</p><p>Misalnya jika kita melakukan decryption pada PAEBABANZIAHAKDXAAAKIU dengan menggunakan <strong>sub key</strong> sama dengan <strong>A </strong>maka hasilnya adalah PAEBABANZIAHAKDXAAAKIU. Dalam gabungan kata tersebut huruf yang paling sering muncul yaitu:</p><ul><li>A sebanyak 8 kali</li><li>K sebanyak 2 kali</li><li>B sebanyak 2 kali</li><li>I sebanyak 2 kali</li><li>Z sebanyak 1 kali</li><li>X sebanyak 1 kali</li></ul><p>Dan angka yang paling sering tidak muncul adalah CLRSOT sebanyak 0 kali (mungkin jika hasil tidak muncul atau 0 lebih dari 6 huruf, akan terdapat perbedaan hasil tergantung dari algoritma perhitungan dan sorting, hasil tersebut tidak masalah selama semua proses dilakukan dengan menggunakan algoritma yang sama).</p><p>Jika diurutkan, huruf yang paling sering muncul pada hasil decryption adalah <strong>AKBIZX</strong> PUDHNEQJVYGFWM <strong>CLRSOT</strong>. Dari hasil tersebut kita bandingkan 6 huruf pertama dan 6 huruf terakhirnya, apakah ada yang termasuk dalam ETAOIN (untuk huruf pertama) atau VKJXQZ (untuk huruf terakhir) untuk kita dapatkan <strong>English Frequency Match Score</strong>. Dari hasil tersebut kita mendapatkan huruf A dan I masuk kepada ETAOIN (6 huruf yang paling sering muncul) sehingga dari hasil decryption ciphertext dengan menggunakan sub keys A kita mendapatkan <strong>English Frequency Match Score </strong>sebesar 2.</p><p>Jika kita melakukannya pada semua sub keys, maka kita akan mendapatkan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*rEqXKp0-4wlGmFX6bZ2-NA.png" /></figure><p><strong>Sub keys</strong> yang hasil decyrptionnya paling mendekati dengan English Frequency Match Score memiliki kemungkinan hubungan yang tinggi dengan <strong>real key</strong>. Hasil <strong>English Frequency Match Score</strong> yang paling banyak dari gabungan 4 kata huruf pertama adalah ‘A’, ‘I’, ’N’, ‘W’, dan ‘X’ (Hasil <strong>English Frequency Match Score</strong> yang kecil = 2, terjadi karena <strong>ciphertext </strong>yang digunakan hanya sedikit, dengan panjangnya <strong>ciphertext </strong>yang digunakan tingkat<strong> </strong>keberhasilan melakukan analisa frekuensi semakin tinggi).</p><p>Selanjutnya kita perlu melakukan kembali decryption dengan 26 <strong>sub keys</strong> pada gabungan 4 kata huruf kedua, ketiga, dan keempat. Maka hasil <strong>English Frequency Match Score</strong> yang didapatkan adalah</p><ul><li>Gabungan 4 kata huruf pertama : A, I, N, W, X</li><li>Gabungan 4 kata huruf kedua : I dan Z</li><li>Gabungan 4 kata huruf ketiga : C</li><li>Gabungan 4 kata huruf keempat : K, N, R, V, Y</li></ul><h4><strong>4. Brute Force pada Subkeys yang Memungkinkan</strong></h4><p>Setelah kita mendapatkan huruf-huruf yang mungkin akan membentuk <strong>real key</strong> dengan panjang key sama dengan 4. Maka kita akan melakukan kombinasi dari huruf-huruf tersebut. Hal ini lebih baik dibandingkan dengan melakukan kombinasi terhadap 26 huruf untuk setiap sub keys, sehingga menghasilkan kemungkinan sebesar 26 x 26 x 26 x 26 = 456, 976. Dengan melakukan analisa frekuensi terlebih dahulu, kita hanya memiliki kemungkinan sebesar 5 x 2 x 1 x 5 = 50 kemungkinan real key yaitu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*s2ADWB-Qb52Vr1ImRfj6WA.png" /></figure><p>Setelah melakukan <strong>Brute Force</strong> pada 50 kemungkinan key tersebut, kita mendapatkan bahwa ciphertext</p><pre>PPQCAXQVEKGYBNKMAZUYBNGBALJONITSZMJYIMVRAGVOHTVRAUCTKSGDDWUOXITLAZUVAVVRAZCVKBQPIWPOU</pre><p>dengan menggunakan <strong>key “WICK</strong>” hasil decryptionnya adalah</p><pre>THOSEPOLICEOFFICERSOFFEREDHERARIDEHOMETHEYTELLTHEMAJOKETHOSEBARBERSLENTHERALOTOFMONEY</pre><p>Keren sekali bukaan !!! kita telah melakukan <strong>pembobolan </strong>pada <strong>Vigenere Cipher</strong>. Prosesnya jauh lebih sulit dibandingkan melakukan pembobolan pada <strong>Caesar Cipher</strong>. Namun dikarenakan telah terdapat algoritma untuk melakukan pembobolan pada <strong>Vigenere Cipher</strong>, algoritma cryptography jenis ini<strong> </strong>tidak banyak digunakan lagi.</p><p>Salah satu algoritma yang menggunakan prinsip dasar yang sama seperti Caesar ataupun Vigenere Cipher (melakukan shifting plaintext) lainnya adalah <strong>One Time Pad</strong>, dimana key yang digunakan adalah hasil dari suatu nilai random (<strong>Pseudo Random</strong> ataupun <strong>True Random</strong>). Namun masih terdapat celah-celah juga untuk melakukan pembobolan. Sehingga munculah algoritma yang lebih tangguh lagi yaitu <strong>DES (Data Encryption Standard)</strong> dan juga <strong>AES (Advanced Encryption Standard)</strong>.</p><h3>Penutup</h3><p>Sekian dulu penjelasan mengenai algoritma <strong>Vigenere Cipher</strong>, selanjutnya saya akan membahas contoh-contoh dari cryptography symmetric lainnya yang sekarang masih umum digunakan yaitu <strong>DES </strong>dan juga <strong>AES</strong>. Pada algoritma ini untuk melakukan pembobolan seperti sebelumnya sangatlah sulit, dibutuhkan komputer dengan kemampuan komputasi yang sangat cepat (Sejauh ini hanya <strong>DES </strong>yang bisa dibobol). Namun terdapat teknik lainnya untuk melakukan pembobolan dengan menggunakan <strong>SCA (Side Channel Attack)</strong> yang akan saya bahas dipostingan-postingan selanjutnya.</p><p>Referensi:</p><ul><li><a href="https://inventwithpython.com/hacking/chapter21.html">https://inventwithpython.com/hacking/chapter21.html</a></li></ul><p>Materi terkait lainnya:</p><ul><li><a href="https://medium.com/@kresna.devara/cryptography-apaan-tuh-fe3d7cff1716">Cryptography… Apaan-tuh?</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a">Cryptography Caesar Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10">Cryptography Vigenere Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-data-encryption-standard-des-e23aac8d5896">Cryptography: Data Encryption Standard (DES)</a></li></ul><blockquote>-Terimakasih-</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5575752f4d10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptography Caesar Cipher]]></title>
            <link>https://kresna-devara.medium.com/cryptography-caesar-cipher-a8e2bac01e7a?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8e2bac01e7a</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 13:48:11 GMT</pubDate>
            <atom:updated>2020-09-30T14:16:14.304Z</atom:updated>
            <content:encoded><![CDATA[<p>Halo, setelah sebelumnya saya membahas mengenai cryptography secara general pada <a href="https://medium.com/@kresna.devara/cryptography-apaan-tuh-fe3d7cff1716">Cryptography… Apaan-tuh?</a> Pada kesempatan kali ini saya akan membahas salah satu contoh dari symmetric cryptography yaitu <strong>Caesar Cipher</strong>. Dan juga saya akan membagikan cara melakukan “pembobolan” pada algoritma ini dengan menggunakan pemograman python. Mari langsung ke pembahasan.</p><h3>Caesar Cipher</h3><p>Caesar cipher merupakan salah satu algoritma yang sudah ada sejak lama dan digunakan pertama kali oleh <strong>Julius Caesar </strong>lebih dari 2000 tahun lalu. Algoritma ini sangat mudah, prinsip dasarnya adalah dengan melakukan subtitusi setiap huruf pada <strong>plaintext </strong>dengan melakukan pergeseran berdasarkan pemetaan huruf dan juga <strong>key </strong>yang digunakan.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*twAKflJqWlZBq518P4n2ew.png" /></figure><p>Contohnya kita gunakan pemetaan dengan 26 huruf alfabet. Pertama-tama kita lakukan pemetaan huruf pada alfabet untuk dapat dilakukan operasi matematika saat proses encryption dan decryption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WbbdVh3WaX013cDXAOu7Fg.png" /></figure><p>Berikut adalah formula yang digunakan untuk encryption dan decryption pada Caesar cipher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*V-VgSia0WN-utPqCmmrEBQ.png" /></figure><p>Dimana:</p><ul><li>E(x) adalah hasil encryption, dimana x adalah dari huruf original atau <strong>plaintext</strong>.</li><li>D(x) adalah hasil decryption, dimana x adalah dari huruf yang telah terdecrypt atau <strong>ciphertext</strong>.</li><li>n adalah nilai atau <strong>key</strong> yang digunakan untuk menggeser huruf.</li><li>Mod 26 digunakan dikarenakan huruf alfabet terdapat 26 buah, sehingga ketika nilai operasinya lebih atau kurang dari 26 maka kita akan tetap dapat melakukan pemetaannya.</li><li>Kita ingin memastikan bahwa hasil dari encryption masih berada dalam rentang dari [0, ukuran_alfabet-1], sehingga kita gunakanlah mod26.</li></ul><h4>Contoh Kasus:</h4><p>Kita akan melakukan encryption pada kalimat “HALO BUDY” dimana <strong>key </strong>yang kita gunakan adalah <strong>4</strong>. Maka untuk menghasilkan ciphertext hal yang kita lakukan adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skphGaOgj-BT631EmctZtg.png" /></figure><p>Sedangkan untuk melakukan decrpytion kita hanya akan melakukan hal yang sebaliknya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xSDoL8P31XOJvWpbqzkeqQ.png" /></figure><p>Mudah sekali bukan!!! Karena kemudahannya inilah algoritma jenis ini sangat mudah untuk dibobol, sehingga untuk menyimpan informasi yang penting, cara seperti ini hampir sudah tidak digunakan.</p><p>Untuk lebih jelasnya saya sudah membuat contoh penggunaan caesar cipher dengan menggunakan pemograman Python pada jupyter notebook yang bisa diakses di Example <a href="https://github.com/kresdev/Crypto/blob/master/Caesar%20Cipher/1%20-%20Caesar%20Cipher.ipynb">Caesar Cipher.</a> <strong>Pada contoh di jupyter notebook, list alphabet ditambahkan “spasi” yang berada pada index 0, sehingga totalnya list alphabet berubah menjadi 27.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*QjgBv6pElhs1V2h3kblOqA.png" /><figcaption>Aplikasi Caesar Cipher pada Python Notebook</figcaption></figure><p>Selanjutnya mari kita bahas bagaimana cara membobolnya.</p><h3>Cracking Caesar Cipher</h3><p>Masalah utama pada Caesar cipher adalah <strong>keyspace </strong>nya yang sangat kecil, yaitu sebanyak dari jumlah alfabet yang digunakan. Dari contoh di atas terdapat 26 pada alfabet, sehingga banyaknya <strong>key </strong>yang memungkinkan hanyalah 26 saja.</p><p>Apa benar begitu???? Mungkin bisa dengan menaikan nilai <strong>key</strong>nya…. mari kita coba. Kita gunakan <strong>key </strong>108 pada contoh encryption sebelumnya.</p><p>Jika kita tambahkan E(x) = (7+108) mod 26 = 11. Nah sama saja bukan !!!</p><p>Kalau begitu bagaimana dengan jika kita mengulang operasinya agar menjadi lebih aman? pertama kita lakukan encryption dengan <strong>key </strong>4, lalu kita lakukan lagi <strong>encryption </strong>dengan<strong> key </strong>5. Sebenarnya hasilnya akan sama saja dengan melakukan <strong>encryption </strong>dengan <strong>key</strong> 9. Sehingga Caesar cipher tidak akan menjadi lebih aman dengan menambahkan operasinya.</p><p>Terdapat dua cara untuk membobol Caesar cipher:</p><h4>Brute Force Attack</h4><p>Dikarenakan <strong>key </strong>yang mungkin digunakan hanya 26, kita dapat memeriksa semua kasusnya dengan kemungkinan key yang ada, prosesnya pun akan berjalan cepat. Dari hasil decryption kita lihat kalimat yang memiliki sebuah arti. Analisa bisa dilakukan secara manual ataupun otomatis, dimana jika kita ingin melakukan secara otomatis, kita perlu sistem tambahan untuk mengecek kemungkinan bahasa yang digunakan. Kita bisa menggunakan dictionary code atau menggunakan Deep Learning.</p><p>Untuk lebih jelasnya saya telah membuat contoh program pada python notebook yang bisa diakses di Example <a href="https://github.com/kresdev/Crypto/blob/master/Caesar%20Cipher/2%20-%20Caesar%20Cipher%20Brute%20Force.ipynb">Caesar Cipher Brute Force</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*mqlyTdv5fShLbwQx6jlILQ.png" /><figcaption>Aplikasi Brute Force Caesar Cipher pada Python Notebook</figcaption></figure><h4>Frequency Analysis</h4><p>Kita dapat melakukan analisa pada distribusi frekuensi dari berbagai macam huruf. Misalnya, dalam bahasa Inggris huruf yang paling sering digunakan adalah E, A, O, I, dan T. Namun dalam suatu kalimat utuh kontribusi “spasi” juga merupakan komponen terbanyak dalam suatu kalimat. Dengan menganalisa distribusi terbanyak kita akan mengetahui <strong>key</strong> yang digunakan.</p><p>Contohnya pada kalimat berikut (tanda baca saya hapus untuk mempermudah pemograman):</p><blockquote>This page shares my best articles to read on topics like health happiness creativity productivity and more The central question that drives my work is How can we live better To answer that question I like to write about science based ways to solve practical problems</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*yL5pZHGVgfh5k5M_K8a6QA.png" /></figure><p>Jika kita lihat dari grafik tersebut, distribusi terbanyak pada kalimat tersebut adalah “spasi”. Maka jika mengasumsikan “spasi” adalah alfabet terbanyak yang muncul pada suatu kalimat, kita bisa menjadikannya sebagai referensi. Kembali lagi untuk melndapatkan <strong>key</strong> dari frekuensi analisis.</p><p>Misalnya kita memiliki ciphertext sebagai berikut:</p><pre>YMNXEUFLJEXMFWJXERCEGJXYEFWYNHQJXEYTEWJFIETSEYTUNHXEQNPJEMJFQYMEMFUUNSJXXEHWJFYN NYCEUWTIZHYN NYCEFSIERTWJEYMJEHJSYWFQEVZJXYNTSEYMFYEIWN JXERCEATWPENXEMTAEHFSEAJEQN JEGJYYJWEYTEFSXAJWEYMFYEVZJXYNTSENEQNPJEYTEAWNYJEFGTZYEXHNJSHJEGFXJIEAFCXEYTEXTQ JEUWFHYNHFQEUWTGQJRX</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*DH4iP8Vexw9rO7KejrAhQA.png" /></figure><p>Dari distribusi frekuensinya kita dapat mengetahui bahwa nilai terbanyak adalah huruf E. Jika kita mengasumsikan nilai real (plaintext) sebelum kalimat diencrypt adalah “spasi”. Maka terjadi pergeseran sebanyak <strong>5</strong> huruf. Sehingga <strong>key </strong>dari caesar cipher mungkin saja adalah <strong>5</strong>.<strong> </strong>Jika kita lakukan decryption dengan <strong>key 5</strong>. Hasilnya adalah</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TrLyvnHDY1NJnitMUsrLgA.png" /></figure><p>Yaaa hasilnya benar !!!</p><p>Jika hal ini terjadi, berarti telah terjadi “information leaking” sehingga kita dapat menganalisanya untuk mendapatkan <strong>key</strong>. Karena nilai distribusi bisa berbeda-beda gunakanlah 4 ranking terbesar dari hasil distribusi frekuensi (alfabet yang paling banyak digunakan).</p><p>Untuk lebih jelasnya saya telah membuat contoh program pada python notebook yang bisa diakses di Example <a href="https://github.com/kresdev/Crypto/blob/master/Caesar%20Cipher/3%20-%20Caesar%20Cipher%20Frequency%20Analysis.ipynb">Caesar Cipher Frequency Analysis</a>.</p><h3>Penutup</h3><p>Sekian dulu penjelasan mengenai algoritma Caiser Cipher, selanjutnya saya akan membahas contoh-contoh dari cryptography symmetric lainnya dan tentunya cara-cara untuk “membobolnya”.</p><p>Materi terkait lainnya:</p><ul><li><a href="https://medium.com/@kresna.devara/cryptography-apaan-tuh-fe3d7cff1716">Cryptography… Apaan-tuh?</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a">Cryptography Caesar Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10">Cryptography Vigenere Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-data-encryption-standard-des-e23aac8d5896">Cryptography: Data Encryption Standard (DES)</a></li></ul><blockquote>-Terimakasih-</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8e2bac01e7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptography… Apaan-tuh?]]></title>
            <link>https://kresna-devara.medium.com/cryptography-apaan-tuh-fe3d7cff1716?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe3d7cff1716</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Sat, 08 Aug 2020 06:42:59 GMT</pubDate>
            <atom:updated>2020-09-30T14:11:09.677Z</atom:updated>
            <content:encoded><![CDATA[<p>Halo pada kesempatan kali ini saya akan membahas hal yang sedikit berbeda dari sebelumnya yaitu …… <strong>Cryptography</strong>. Mungkin bagi sebagian orang hal ini tidak familiar. Saya sendiri baru tau hal ini kurang dari setahun yang lalu saat masuk ke kantor yang sekarang ini hehehe. Tapi hal ini cukup menarik karena <strong>cryptography </strong>sangat penting untuk kehidupan kita khususnya saat banyak hal beralih ke arah digital. Oke sudah dulu intermezonya, mari kita lanjut ke pembahasannya.</p><h3>Jadi Apa Itu <strong>Cryptography</strong>?</h3><blockquote><strong>Cryptography </strong>merupakan sebuah metode/teknik untuk membuat komunikasi yang lebih aman dari pihak ketiga yang kita tidak inginkan</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKuoHd1dLVC5pzOtxh92kg.png" /></figure><p>Kenapa sih itu sangat penting?</p><p>Bayangkan saja…. misalnya saat perang dunia dahulu, untuk mengirimkan informasi antar pasukan sekutu dibutuhkan kurir pengantar informasi. Dan apabila terjadi sesuatu terhadap kurir pengantar, informasi yang dikirimkan tidak boleh sampai bocor ke tangan musuh. Sehingga informasi itu perlu diamankan dengan suatu teknik agar hanya orang-orang tertentu saja yang dapat membacanya dan rahasia tidak akan bocor.</p><p>Hal tersebutlah yang membuat ilmu cryptography sangat populer setelah perang dunia ke II dan terus berkembang hingga sampai sekarang. Saat ini <strong>cryptography </strong>digunakan untuk: melindungi <strong>privasi data</strong>, mengamankan berbagai macam key seperti password, dan juga berbagai komunikasi rahasia lainnya.</p><h3>Fungsi Cryptography</h3><ul><li><strong>Confidentiality</strong>: Memastikan bahwa hanya orang yang berwenang yang dapat mengakses data.</li><li><strong>Integrity</strong>: Memastikan bahwa informasi tidak diubah (internal ataupun eksternal) selama pengiriman.</li><li><strong>Authentication</strong>: Membuktikan identitas seseorang atau asal mula dokumen.</li><li><strong>Non-repudiation</strong>: Memastikan bahwa seseorang tidak dapat menyangkal validitas suatu data.</li></ul><h3>Istilah-Istilah Penting Pada Cryptography</h3><ul><li><strong>Plaintext</strong>: Pesan yang akan kita amankan (pesan yang masih bisa dibaca).</li><li><strong>Ciphertext</strong>: Pesan yang telah diolah sehingga tidak dapat dibaca lagi secara langsung.</li><li><strong>Encryption</strong>: Proses untuk mengolah plaintext untuk menjadi ciphertext.</li><li><strong>Decryption</strong>: Proses untuk mengolah ciphertext untuk menjadi plaintext kembali.</li><li><strong>Key</strong>: Kunci yang digunakan untuk mengolah cryptography, baik itu pada saat encryption ataupun decrypion.</li><li><strong>Algorithm</strong>: Metode yang digunakan untuk melakukan encryption atau decrytpion.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*jk6LJdaIqB8D_fZogtJTow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*bjq843W_Rrm2gyTuUGNutQ.png" /><figcaption>Proses Encryption dan Decryption</figcaption></figure><h3>Jenis-jenis Cryptography</h3><p>Secara garis besar cryptography terdiri dari dua jenis:</p><h4>Asymmetric</h4><p>Pada <strong>cryptography </strong>jenis ini, terdapat dua key yang digunakan. Yaitu: <strong>public key</strong> dan juga <strong>private key</strong>. Baik pengirim ataupun penerima akan memiliki private keynya masing-masing (tidak dibagikan satu sama lain). <strong>Key </strong>yang dibagikan satu sama lain adalah <strong>public key</strong>.</p><p>Contoh kasusnya:</p><p>Jika Alice ingin mengirimkan pesan kepada Bob, Alice perlu melakukan <strong>encryption </strong>dengan menggunakan <strong>public key</strong> milik Bob, sehingga ketika pesan yang sudah terencrypt tersebut sampai ke Bob, Bob dapat melakukan <strong>decyrption </strong>dengan menggunakan <strong>private key</strong>nya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLvlG40PT7jM1-PtTkADXg.png" /></figure><p><strong>Cryptography asymmetric </strong>memiliki tingkat keamanan yang lebih tinggi dikarenakan <strong>key </strong>yang dikirimkan satu sama lain melalui pihak ketiga adalah <strong>public key</strong>, sehingga hanya orang spesifik saja yang dapat membacanya dengan menggunakan <strong>private key</strong>. Namun cryptography ini memiliki kelemahan yaitu pada prosesnya yang <strong>lebih lambat</strong> dan jumlah data yang <strong>lebih sedikit</strong>.</p><p>Contoh algoritma atau metode yang menggunakan cryptography jenis ini adalah: <strong>Diffie-Hellman</strong>, <strong>RSA</strong>, dan <strong>Elliptic Curve Cryptography (ECC)</strong>.</p><h4>Symmetric</h4><p>Pada <strong>cryptography </strong>jenis ini, <strong>key </strong>yang digunakan hanya satu jenis saja. <strong>Key </strong>ini digunakan baik untuk melakukan <strong>encryption </strong>ataupun <strong>decryption</strong>. Sehingga baik pengirim ataupun penerima menggunakan <strong>key </strong>yang sama.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*z4Palrk3Dl0CgaPp61qkDQ.png" /></figure><p><strong>Cryptography symmetric </strong>memiliki keunggulan pada prosesnya yang <strong>lebih cepat</strong> dibandingkan asymmetric, data yang dikirimkan juga bisa dalam jumlah yang <strong>lebih besar</strong>. Permasalahan pada cryptography jenis ini adalah <strong>key </strong>nya harus dilakukan pertukaran satu sama lain, dan memungkinkan terjadinya keterlibatan oleh pihak ketiga. Sehingga kita membutuhkan proses lain untuk mengirimkan <strong>key </strong>ini secara lebih aman, misalnya dengan melakukan proses <strong>cryptography asymmetric</strong>. Namun, pada pengiriman data proses yang digunakan tetap menggunakan <strong>cryptography symmetric</strong>.</p><p>Contoh algoritma atau metode yang menggunakan cryptography jenis ini adalah: <strong>Caesar-cipher</strong>, <strong>DES</strong>, <strong>3DES</strong>, <strong>AES</strong>.</p><h3>Penutup</h3><p>Sekian dulu penjelasan <strong>cryptography </strong>secara umum, selanjutnya saya akan membahas contoh-contoh dari cryptography <strong>symmetric </strong>dan <strong>asymmetric</strong> dan juga cara melakukan “<strong>cracking</strong>”nya.</p><p>Materi terkait lainnya:</p><ul><li><a href="https://medium.com/@kresna.devara/cryptography-apaan-tuh-fe3d7cff1716">Cryptography… Apaan-tuh?</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-caesar-cipher-a8e2bac01e7a">Cryptography Caesar Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-vigenere-cipher-5575752f4d10">Cryptography Vigenere Cipher</a></li><li><a href="https://medium.com/@kresna.devara/cryptography-data-encryption-standard-des-e23aac8d5896">Cryptography: Data Encryption Standard (DES)</a></li></ul><blockquote><strong>-Terimakasih</strong>-</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe3d7cff1716" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial Arduino (Part 1) — Tinkercad dan Simulasi Arduino]]></title>
            <link>https://kresna-devara.medium.com/tutorial-arduino-part-1-tinkercad-dan-simulasi-arduino-ee0b10bac653?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee0b10bac653</guid>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Thu, 21 May 2020 08:14:32 GMT</pubDate>
            <atom:updated>2020-05-21T08:40:28.789Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tutorial Arduino (Part 1) — Tinkercad dan Simulasi Arduino</h3><p>Hallo setelah pembahasan sebelumnya mengenai Arduino. Pada kali ini saya akan membahas praktek langsung cara penggunaanya. Pada artikel sebelumnya saya telah membahas cara <a href="https://medium.com/@kresna.devara/apa-itu-arduino-7d1e192686cd">pemrograman Arduino</a> dengan menggunakan Arduino IDE. Namun pada kali ini saya akan mengenalkan tools yang sangat berguna untuk kita melakukan simulasi elektronik dan juga Arduino tanpa harus memiliki barangnya secara fisik, menarik bukan!!! Ya namanya adalah <a href="https://www.tinkercad.com/"><strong>Tinkercad</strong></a>, mari kita bahas terlebih dahulu.</p><h3>Tinkercad</h3><blockquote>Tinkercad merupakan tools online gratis untuk membantu para makers ataupun hobbyist untuk mendesign dan menciptakan produknya sendiri. Pada awalnya tools ini hanya memiliki fitur 3D design yang sederhana, namun saat ini Tinkercad telah dikembangkan dengan tools baru yang bernama <strong>“Circuit”</strong> untuk melakukan simulasi rangkaian elektronika sederhana dan juga Arduino.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JADMa_a6LE6Jk2d1zzVZfw.jpeg" /><figcaption>Tinkercad</figcaption></figure><p>Langsung saja kita coba menggunakan Tinkercad.</p><blockquote>1. Masuk lah ke halaman Tinkercad.com, jika kalian belum memiliki akun Tinkercar daftarkan terlebih dahulu menggunakan email.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pc-fd9BsPHYWmZ5avmJy4A.jpeg" /><figcaption>1. Halaman Sign in Tinkercad</figcaption></figure><blockquote>2. Pilihlah circuits pada Tinkercad dashboard, dan mulailah membuat circuit baru.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RyoxLz9a0ukWI3YU839xxg.jpeg" /><figcaption>2. Halman dashboard Tinkercad</figcaption></figure><blockquote>3. Carilah Arduino dan LED dengan menggunakan search bar pada bagian kanan Tinkercad. Sambunglah Cathode LED pada pin GND Arduino, dan Anode LED pada pin 13 Arduino seperti pada gambar.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PXNRgyfMifR_LS_m5lvjBQ.jpeg" /><figcaption>3. Merangkai Arduino</figcaption></figure><blockquote>4. Klick code pada bagian kanan atas, dan pilihlah Text, kita akan melakukan pemrograman langsung dengan menggunakan bahasa C. Tulislah code seperti pada di bawah ini.</blockquote><pre>//1. Tutorial Tinkercad</pre><pre>int LED = 13; // menginisialisasi nama lampu LED untuk pin13</pre><pre>void setup()<br>{<br> pinMode(LED,OUTPUT); //inisialisasi pin LED(13) sbg output<br>}</pre><pre>void loop()<br>{<br> digitalWrite(LED,HIGH); //pin LED(13) HIGH(menjadi 5v)<br> delay(1000); //menunda instruksi sblmnya selama 1 detik<br> digitalWrite(LED,LOW); //pin LED(13) LOW(menjadi 0v)<br> delay(1000);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U-6DzWUqhm4u7G9FDx_cUQ.jpeg" /><figcaption>4. Memprogram Arduino</figcaption></figure><blockquote>5. Klick Start Simulation. Tara!!! Arduino sudah berjalan, LED akan berkedip-kedip setiap 1 detik sekali.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3KfbWt4PNvb2wg2bd9dMw.jpeg" /><figcaption>5. Simulasi Arduino</figcaption></figure><h3>Pembahasan Code Arduino</h3><p>Setelah berhasil melakukan simulasi pada Tinkercad mari kita bahas rahasia dari code-code di atas.</p><pre>//1. Tutorial Tinkercad</pre><p>Pada pemrograman Arduino semua tulisan yang dimulai dengan tanda // hingga akhir baris diperlakukan sebagai komentar.</p><pre><em>int LED = 13; // menginisialisasi nama lampu LED untuk pin13</em></pre><p>Pernyataan tersebut digunakan untuk menginisialisasi nama variabel yang dimaksudkan bahwa variabel LED berisikan 13. Angka 13 dimaksudkan pin no 13 pada Arduino.</p><pre>void setup()<br>{<br>}<br>void loop()<br>{<br>}</pre><p>Terdapat dua fungsi utama pada Arduino yaitu void setup() dan void loop(). Dua fungsi ini wajib ada, void setup merupakan fungsi yang pertama kali dijalankan oleh Arduino, sedangkan void loop merupakan fungsi yang akan terus berulang kali dijalankan selama Arduino masih menyala.</p><pre>pinMode(LED, OUTPUT);</pre><p>Perintah tersebut dimaksudkan untuk menginisalisasikan pin, apakah pin tersebut akan menjadi input ataukah output. Input berarti pin tersebut akan menerima masukan tegangan sedangkan output berarti pin tersebut akan memberikan tegangan. struktur untuk fungsi dari pin adalah</p><pre>pinMode(<em>NomorPin, Kondisi); </em></pre><p>Pernyataan program pada Arduino harus selalu diakhiri dengan titik koma “;” sama halnya dengan suatu kalimat yang diakhiri dengan titik, sedangkan komentar tidak perlu diakhiri dengan titik koma.</p><pre>digitalWrite(LED, HIGH);<br>digitalWrite(LED, LOW);</pre><p>Perintah digitalWrite digunakan untuk memberikan instruksi apakah pin tersebut memberikan tegangan atau tidak. Struktur untuk output pin adalah</p><pre> digitalWrite(<em>NomorPin, Kondisi);</em> </pre><p>Kondisi dapat diubah menjadi HIGH, ataupun LOW tergantung kebutuhan. High berarti pin tersebut memberikan tegangan sebesar 5v sedangkan LOW memberikan tegangan sebesar 0v atau pin dalam kondisi mati.</p><pre>delay(1000);</pre><p>Perintah tersebut digunakan untuk membuat Arduino tidak melakukan apapun selama 1000 milidetik atau 1 detik. Dengan demikian, selama waktu itu, LED tetap menyala.</p><h3>Tantangan !!!</h3><p>Cobalah untuk menggantikan pin 13 menjadi pin lainnya 12,11,10 dst dan coba gantilah delay pertama ataupun delay kedua dengan angka lain sehingga dapat menimbulkan efek yang berbeda. Contohnya delay pertama 3000 milidetik sedangkan delay kedua tetap 1000 milidetik. Apakah yang terjadi? Sekian dulu artikel pada kali ini, tunggu untuk artikel-artikel selanjutnya !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee0b10bac653" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apa itu Arduino?]]></title>
            <link>https://kresna-devara.medium.com/apa-itu-arduino-7d1e192686cd?source=rss-5fcbba73ef2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d1e192686cd</guid>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[robots]]></category>
            <category><![CDATA[microcontrollers]]></category>
            <category><![CDATA[pemula]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Kresna Devara]]></dc:creator>
            <pubDate>Thu, 14 May 2020 13:37:48 GMT</pubDate>
            <atom:updated>2020-05-21T08:38:04.863Z</atom:updated>
            <content:encoded><![CDATA[<p>Hallo pada kali ini saya akan membahas mengenai Arduino. Sebelum mengenal Arduino lebih jauh, mari kita lihat terlebih dahulu berbagai macam alat-alat elektronik yang ada.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KOuN-7d-26jUTHQYg5Dv2g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*Q8Xtz_4zVuPs5WL3Ubewfw.jpeg" /><figcaption>Robot, Thermometer, dan Vending Machine</figcaption></figure><p>Mungkin kalian telah melihat berbagai macam jenis robot, alat vending machine, thermometer, ATM, Televisi dan lain sebagainya. Perangkat-perangkat ini dibangun dengan menggunakan suatu chip mikrokontroler, ataupun mikroprosesor. Chip ini adalah “otak” dari peralatan-peralatan tersebut. Dengan chip tersebut baik robot ataupun vending machine dapat melakukan suatu pekerjaan yang spesifik. Nah Arduino ini sendiri merupakan salah satu jenis dari mikrokontroler.</p><h3><strong><em>Apasih Arduino itu?</em></strong></h3><p>Menurut Website Arduino:</p><blockquote>Arduino is an open-source electronics platform based on easy-to-use hardware and software. <a href="https://www.arduino.cc/en/Main/Products">Arduino boards</a> are able to read inputs — light on a sensor, a finger on a button, or a Twitter message — and turn it into an output — activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the <a href="https://www.arduino.cc/en/Reference/HomePage">Arduino programming language</a> (based on <a href="http://wiring.org.co/">Wiring</a>), and <a href="https://www.arduino.cc/en/Main/Software">the Arduino Software (IDE)</a>, based on <a href="https://processing.org/">Processing</a>.</blockquote><p>Dengan kata lain Arduino adalah suatu perangkat elekronik terbuka yang mampu merubah suatu masukan (input) menjadi satu perintah keluaran (output) dengan memanipulasi suatu proses yang dilakukan dengan menggunakan bahasa pemograman.</p><h3><strong>Arduino Board</strong></h3><p>Arduino Board sendiri merupakan suatu papan elektronik berukuran sebesar kartu kredit berbasis mikrokontroler yang dapat diprogram. Terdapat berbagai macam jenis Arduino contohnya: Arduino UNO, Mega, Nano, Duemilanov dan lain sebagainya. Arduino UNO merupakan salah satu yang paling populer digunakan sebagai pembelajaran, karena bentuknya yang sederhana dan dapat dengan mudah untuk digabungkan dengan perangkat elektronik lainnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*blfS-UMpp-LueBaBNGWAEA.png" /><figcaption>Arduino UNOPinout Diagram</figcaption></figure><p>Arduino UNO menggunakan chip mikrokontroler ATMega 328P dengan crystal oscillator 16 MHz. Dengan 14 pin Digital yang dapat digunakan sebagai Input/Output, 6 pin sebagai input Analog dan output digital, serta 6 pin PWM (Pulse Width Modulation) yang dapat digunakan untuk mengontrol motor. Arduino UNO dilengkapi dengan SRAM berukuran 2KB, flash memory 32KB dan EEPROM untuk menyimpan data.</p><h3><strong>Arduino IDE</strong></h3><p>Untuk memprogram Arduino, kita dapat menggunakan software Arduino<a href="https://www.arduino.cc/en/Main/Software"> IDE (Integrated Development Environment)</a> yang telah disediakan oleh Arduino. Software tersebut telah berisi code editor, compiler, dan juga sebuah uploader sehingga pengguna dapat dengan mudah menggunakan Arduino secara langsung. Program Arduino disebut dengan “sketches”, dan ditulis dengan menggunakan bahasa yang hampir sama dengan bahasa C. Berikut adalah contoh tampilan dari Arduino IDE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dJw1QeTpa6RMRAQxQbEQw.png" /><figcaption>Arduino IDE</figcaption></figure><p>Sebenarnya masih banyak cara lain untuk dapat menggunakan Arduino selain menggunakan Arduino IDE. Kita masih dapat menggunakan editor lain seperti Visual Studio ataupun Eclipse dengan menambahkan plugin Arduino. Namun hal ini akan lebih rumit sehingga membutuhkan waktu setup yang lebih lama lagi. Untuk saat ini mari kita gunakan Arduino IDE Terlebih dahulu.</p><h4><strong>Sekian pembahasan singkat mengenai Arduino. Tunggu tutorial-tutorial selanjutnyaa, selamat belajar !!!!</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d1e192686cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>