<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pedro Matias de Araujo</title>
    <description>The latest articles on DEV Community by Pedro Matias de Araujo (@pemtajo).</description>
    <link>https://dev.to/pemtajo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F94502%2F6693e160-f676-44f0-8cb4-6b4a53ea9edd.png</url>
      <title>DEV Community: Pedro Matias de Araujo</title>
      <link>https://dev.to/pemtajo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pemtajo"/>
    <language>en</language>
    <item>
      <title>Adding badges to your Github profile</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Tue, 09 Mar 2021 18:03:08 +0000</pubDate>
      <link>https://dev.to/pemtajo/how-to-improve-your-github-profile-by-adding-badges-gib</link>
      <guid>https://dev.to/pemtajo/how-to-improve-your-github-profile-by-adding-badges-gib</guid>
      <description>&lt;h4&gt;
  
  
  Badges are a great way to measure professional skills, so why not put them on your GitHub profile?
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/XEyYvdfEZTCaaOH3Xi/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/XEyYvdfEZTCaaOH3Xi/giphy.gif"&gt;&lt;/a&gt;&lt;br&gt;
Recently, I started looking for ways to improve my professional skills and with that, I gained several &lt;a href="https://www.youracclaim.com" rel="noopener noreferrer"&gt;Acclaim&lt;/a&gt; badges that are easily shared on LinkedIn, but not so easily shared on Github. And that led me to think of easy ways to automate this.&lt;/p&gt;

&lt;p&gt;Over time, I became a huge fan of automation.&lt;/p&gt;

&lt;p&gt;In programming and day-to-day tasks, It’s important not to waste time on rework.&lt;/p&gt;

&lt;p&gt;I was already thinking about automatically updating my Github with these badges as I said before and this mentality joined my desire to create a project where I could learn more about creating actions on Github.&lt;/p&gt;

&lt;p&gt;This is a good way to show more effectively what I am studying and still have the opportunity to learn more in the process, consequently generating value for what I am doing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creation the code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/ZVik7pBtu9dNS/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ZVik7pBtu9dNS/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started to study the &lt;a href="https://www.youracclaim.com" rel="noopener noreferrer"&gt;Acclaim&lt;/a&gt; to see if there were any APIs to receive these values, but I didn’t find anything for the user, just for organizations.&lt;/p&gt;

&lt;p&gt;As it was only necessary the name, the image, and possibly the link of the badge I had the idea of ​​using a web scraping on the public website to include the values ​​that I needed. And it worked very well, with that I was able to receive the values ​​and generate HTML tags for the markdown.&lt;/p&gt;

&lt;p&gt;But there was still the challenge of creating action on Github and the problem was simpler than I thought. Was just create an &lt;a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions" rel="noopener noreferrer"&gt;action.yml&lt;/a&gt;, put all my code in the docker and it worked as expected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using
&lt;/h3&gt;

&lt;p&gt;Setting up on your GitHub profile is simple, you just need to do this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;hit New workflow, set up a workflow yourself, delete all the default content GitHub made for you.&lt;/li&gt;
&lt;li&gt;Copy the following code and paste it to the new workflow you created at step 1:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Update badges

on:
  schedule:
    # Runs at 2am UTC
    - cron: "0 2 * * *"
jobs:
  update-readme:
    name: Update Readme with badges
    runs-on: ubuntu-latest
    steps:
      - name: Badges - Readme
        uses: pemtajo/badge-readme@master
          ACCLAIM_USER: &amp;lt;username_acclaim&amp;gt; # optional, but default will use the same from github
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add a comment to your README.md like this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!--START_SECTION:badges--&amp;gt;
&amp;lt;!--END_SECTION:badges--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The result will look like this
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F907%2F1%2AdIjSHN3rUAg8vsZish00MA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F907%2F1%2AdIjSHN3rUAg8vsZish00MA.png" alt="https://github.com/pemtajo"&gt;&lt;/a&gt;&lt;a href="https://github.com/pemtajo" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://github.com/pemtajo" rel="noopener noreferrer"&gt;https://github.com/pemtajo&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to contribute
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/pemtajo/badge-readme" rel="noopener noreferrer"&gt;pemtajo/badge-readme&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More details on README&lt;/p&gt;

&lt;p&gt;Feel free to fork and use.&lt;/p&gt;

&lt;p&gt;If you have any problems or have another badge supplier, let’s talk and improve the project.&lt;/p&gt;

&lt;p&gt;See you soon!&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>badges</category>
      <category>acclaim</category>
      <category>automation</category>
    </item>
    <item>
      <title>How American football makes me a better developer</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Fri, 21 Jun 2019 15:53:00 +0000</pubDate>
      <link>https://dev.to/pemtajo/how-american-football-makes-me-a-better-developer-47he</link>
      <guid>https://dev.to/pemtajo/how-american-football-makes-me-a-better-developer-47he</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg12pga7jc7p2ey725o4e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg12pga7jc7p2ey725o4e.jpg"&gt;&lt;/a&gt;&lt;br&gt;
I had never heard of American football until I started my undergraduate degree in computer science.&lt;/p&gt;

&lt;p&gt;I was living for the first time alone, in another city, being a new guy in a new place, so when a friend asked me if I wanted to start training on the new football team, I thought "ok, why not?" and that changed my whole life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why changed?
&lt;/h2&gt;

&lt;p&gt;I trained at &lt;a href="https://www.instagram.com/maringapyros/" rel="noopener noreferrer"&gt;Maringá Pyros&lt;/a&gt; for five years. On the team I was a RB / WR, after that, I was a football judge for a year, and after a few years I became a sports commentator for a local radio station in Brazil, where I learned a lot about things that help me until now in my professional life.&lt;/p&gt;

&lt;h1&gt;
  
  
  Workgroup
&lt;/h1&gt;

&lt;p&gt;How football is a collective sport, teamwork is essential to make things work. Jointly it is essential to train, coordinate and engage the team as a whole to make the plays successful and consequently win the game. I find it amazing how in the same way that it works in football, in a software team, everyone has to be aligned to ensure the success of an operation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Motivation
&lt;/h1&gt;

&lt;p&gt;It's simple if you're an 80 kg guy with the ball in the middle of the field and the only way to bet on the game is to hit a guy with 150 kg, what do you do? Do you stop? You cry? Do you give up or come back? There are no such options, the only way is to move forward, the whole team trusts you, the whole team is doing their best so you can do your best job, all you have to do is give it all of yourself .&lt;/p&gt;

&lt;p&gt;How can the last situation be applied to a software team? The principle is the same.&lt;br&gt;
If you have a problem, you can not just stop and give up. You can not drop everything and fail with your team. You need to trust on the team you have on your side and you have to do your best to jointly complete the task and make things work.&lt;/p&gt;

&lt;h1&gt;
  
  
  Competition
&lt;/h1&gt;

&lt;p&gt;The biggest competition is not against the other peers, the biggest competition that exists is you against you. You should seek your best every day, seek out your weaknesses and make them better day by day, seek your strength and train your skills every day. You have to give everything you have, every second and every moment of your life.&lt;/p&gt;

&lt;p&gt;But here's an important tip, I'm not saying to exhaust your mind and push beyond your limits, I'm telling you to take care of your brain and your abilities as a muscle, they need rest, they need good nutrition and also need good training. Having the mentality of an athlete is important, for learn to respect your limits and improve yourself.&lt;/p&gt;

&lt;h1&gt;
  
  
  Leadership
&lt;/h1&gt;

&lt;p&gt;I'm not a leader, but I'm always looking to encourage and motivate the team that I'm a part of. At times we need to inject motivation into our team, we need everyone to keep fighting and sometimes you can be the determining factor for your team not to give up. Even without being a leader, I'm always willing to hold everyone and help everyone.&lt;br&gt;
Being in an office is not much different than being on a sideline. The sideline is much more emotional and there we can scream, encourage and help everyone at the base of the scream. While in the office, you can't shout to motivate someone. But it is important for you to do the same job of encouraging your colleague and boosting colleague morale when he has to deal with a two-week bug.&lt;br&gt;
I'm good at it? No. But I'm always trying.&lt;/p&gt;

&lt;h1&gt;
  
  
  Communication
&lt;/h1&gt;

&lt;p&gt;This is a new skill that I am having to improve in my life, I have never been a good communicator and I have accepted the challenge of improving it. I significantly improved my speech when I started a job as a sports commentator. In the first audios I did, I needed to write and read so I could record. And yet it took several audios to conquer more or less what I thought acceptable. I could not think and speak at the same time. And it took a lot of training to get better.&lt;/p&gt;

&lt;p&gt;Now, I'm significantly improving the way I speak and hitting the tone of my voice, I am not perfect, but now I believe that little by little I am getting better than yesterday. And that has had an impact on my work as well, speaking clearly, with a clear tone of voice and being able to pass on to the other what I'm saying clearly is a skill that makes all the difference at work.&lt;br&gt;
For me it was a great victory.&lt;/p&gt;

&lt;h1&gt;
  
  
  Responsibility
&lt;/h1&gt;

&lt;p&gt;I failed with my team several times, three times I had the ball to win the game and I failed. I've already failed everyone who trusts me, and I've never put my mistake in anyone else.&lt;/p&gt;

&lt;p&gt;There is no excuse, no matter the reason, if I failed, I take full responsibility for it.&lt;/p&gt;

&lt;p&gt;This is yet another teaching of American football that has made a big impact on my life of dev because the principle is the same, you should never put other people in responsibility for your mistakes. I prefer to sleep well at night, knowing that I have made the right choice and knowing that I can improve so that these mistakes do not happen anymore.&lt;/p&gt;

&lt;h1&gt;
  
  
  The game
&lt;/h1&gt;

&lt;p&gt;The sport is incredible, and the more you learn, the more you have to study. Making the right decision in milliseconds of pressure, keeping calm is what separates a good player from incredible players.&lt;/p&gt;

&lt;p&gt;Parallel to development, this skill makes a big difference to enable you to do a good job even when the sky is on fire.&lt;/p&gt;

&lt;p&gt;So I write those words to show you that other activities that have nothing to do with the work itself can make you a better developer. If you have other hobbies that have improved your developer work, put in the comments below and let's talk.&lt;/p&gt;

&lt;p&gt;Cheers.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>Creating a blockchain with less 100 code lines</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Wed, 03 Apr 2019 01:40:48 +0000</pubDate>
      <link>https://dev.to/pemtajo/creating-a-blockchain-with-less-100-code-lines-5aba</link>
      <guid>https://dev.to/pemtajo/creating-a-blockchain-with-less-100-code-lines-5aba</guid>
      <description>&lt;h3&gt;
  
  
  Creating a blockchain with less than 100 code lines
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AQADifoe26ax-QP_9" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F0%2AQADifoe26ax-QP_9"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@thoughtcatalog?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Thought Catalog&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The basic concept of blockchain is very simple: &lt;em&gt;a distributed database that maintains a continuously growing list of ordered records.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The blockchain is a term normally associated with Bitcoin and/or Ethereum, but blockchain is more than that, blockchain is the technology behind these, and behind any other cryptocurrency.&lt;/p&gt;

&lt;p&gt;There is a lot of other’s uses for blockchain, per example, games (&lt;a href="https://www.cryptokitties.co/" rel="noopener noreferrer"&gt;CryptoKitties&lt;/a&gt;) or also blockchain+IOT(Internet of things), and this is just the start for the technology.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F805%2F1%2ATV_02Syq-SWRChiXigN8Rw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F805%2F1%2ATV_02Syq-SWRChiXigN8Rw.png"&gt;&lt;/a&gt;One simply image about the blockchain’s concept&lt;/p&gt;

&lt;p&gt;The blockchain is, like the name said, one &lt;em&gt;chain of blocks,&lt;/em&gt; so, we have the first class, the Block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0D3Uc7yIyR7Kv-n7Fq6vXA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2A0D3Uc7yIyR7Kv-n7Fq6vXA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this stage my block has the attributes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;index — the block index the position in the chain&lt;/li&gt;
&lt;li&gt;timestamp — date and time that the block was added in Blockchain&lt;/li&gt;
&lt;li&gt;data — the data value, in other words, what you want to save&lt;/li&gt;
&lt;li&gt;previous hash — the hash of the block index -1&lt;/li&gt;
&lt;li&gt;hash — the hash of the block&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don’t know what’s hash, I did explain in my last post &lt;a href="https://dev.to/pemtajo/an-overview-about-hash-functions-theory-and-security-139e"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You will see some things interesting in the picture and here I will explain a little bit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;let more OOP the function &lt;em&gt;isValid&lt;/em&gt; is for each block respond if he is valid&lt;/li&gt;
&lt;li&gt;The constructor defines all the things in the block&lt;/li&gt;
&lt;li&gt;the function “update” is to update the &lt;em&gt;dict&lt;/em&gt; when reading from a file, this is for saving the data for future&lt;/li&gt;
&lt;li&gt;calculating the hash for previously saved files, to convert always to the same encode, because, differents encodes have different characters and different characters produce different hashes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So this is a chain valid, if the block was changed, the current block will know, and make yourself invalid, and if any previous block was changed, the chain will know, and all the chain will be invalid. That is the concept that makes the data save in Blockchain immutable.&lt;/p&gt;

&lt;p&gt;So looking in our second class, Blockchain, it looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ARKxCwUFAebYgfkMjvJCeZA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2ARKxCwUFAebYgfkMjvJCeZA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, the blockchain class create the blocks and look for any problem in the chain, and this class is responsible for saving in a simple JSON file and read from him. Our first version blockchain is ready!! \o/&lt;/p&gt;

&lt;p&gt;All the code is below, you can execute and see the output&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In this version of our blockchain, we not implemented the &lt;a href="https://en.wikipedia.org/wiki/Proof-of-work_system" rel="noopener noreferrer"&gt;Proof of Work&lt;/a&gt;, the idea first is created the blockchain and guaranteed the chain’s integrated. That will be my next step.&lt;/p&gt;

&lt;p&gt;I created a project that you can follow in &lt;a href="https://github.com/pemtajo/blockchain" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, I will increment more and more my blockchain, if you have interesting just follow me, I will write some posts about all the process.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S: I am not an expert in the blockchain, so any problem, code fix, or tips, this is will be very welcome to comment below and will help some peoples too. Or you can talk to me privately in the&lt;/em&gt; &lt;a href="https://www.linkedin.com/in/pedromaraujo/" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See you soon!&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>cryptography</category>
      <category>blockchain</category>
      <category>python</category>
    </item>
    <item>
      <title>An overview about hash functions: Theory and Security</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Thu, 22 Nov 2018 01:51:13 +0000</pubDate>
      <link>https://dev.to/pemtajo/an-overview-about-hash-functions-theory-and-security-139e</link>
      <guid>https://dev.to/pemtajo/an-overview-about-hash-functions-theory-and-security-139e</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F640%2F1%2AHuCZw-nGPkTsaORer4g4jg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F640%2F1%2AHuCZw-nGPkTsaORer4g4jg.jpeg"&gt;&lt;/a&gt;&lt;a href="https://pemtajo.github.io/hash_teoria_seguranca/" rel="noopener noreferrer"&gt;Portuguese version&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A more common definition for hash functions would be “a function that maps a string of bits of arbitrary length to a fixed-length bit string”.&lt;/p&gt;

&lt;p&gt;Hash functions are unidirectional, a surjective function that does not allow reverse, so it is easy to calculate the hash value from any input of arbitrary length.&lt;/p&gt;

&lt;p&gt;In contrast, it is harder to return to the previous value of the message from a given hash value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hash Properties
&lt;/h3&gt;

&lt;p&gt;For a cryptographic application, there are three desirable properties:&lt;/p&gt;

&lt;h4&gt;
  
  
  Collision Resistance
&lt;/h4&gt;

&lt;p&gt;It is computationally impracticable to find any pair (x, y) such that H(x)=H(y)&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Pre-image resistance&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;For any value h given, it is computationally impracticable to find x such that H(x) = h.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Second pre-image resistance&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;For any block of data x, it is computationally impracticable to find y different from x, such that H(y) = H(x).&lt;/p&gt;

&lt;p&gt;The ideal situation is that every hashed value generated is really unique for each input value, but this is not possible. In the hash functions the possible hash values to be generated are finite, since they have a fixed output size and because the input size is theoretically infinite, by the Pigeonhole principle, there will be collisions with two distinct entries, resulting in the same hash .&lt;/p&gt;

&lt;p&gt;However, these functions have been constructed to minimize valid collisions, ie, it is very unlikely that two messages that have meaning in context will result in the same hash.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hash usage examples
&lt;/h3&gt;

&lt;p&gt;Hash functions have a wide variety of security uses, such as:&lt;/p&gt;

&lt;h4&gt;
  
  
  Message Authentication
&lt;/h4&gt;

&lt;p&gt;Mechanism or service used to verify the integrity of a message; ensures that the information received is the same as the message sent (without modification, insertion, deletion or replay);&lt;/p&gt;

&lt;h4&gt;
  
  
  Digital signatures
&lt;/h4&gt;

&lt;p&gt;The summary value of a message is encrypted with the sender’s private key, any user who has the public key can verify the integrity of the message that is associated with the digital signature;&lt;/p&gt;

&lt;h4&gt;
  
  
  Password file
&lt;/h4&gt;

&lt;p&gt;A summary of a password is stored in a file of the operating system instead of storing the password, in case the password file is violated, the attacker will only be able to obtain the hash of the password;&lt;/p&gt;

&lt;h4&gt;
  
  
  Detection of intruders and viruses
&lt;/h4&gt;

&lt;p&gt;For each F file of the system, the hash H(F) is also stored, if there is any change in F, it will be perceived;&lt;/p&gt;

&lt;h4&gt;
  
  
  Pseudorandom function family (PRF) or Pseudorandom number generator (PRNG)
&lt;/h4&gt;

&lt;p&gt;For symmetric keys generation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Blockchain
&lt;/h4&gt;

&lt;p&gt;The data in the blockchain are “hashes” in each block. If the block changes, ie someone tried to change how many bitcoins, for example, they had or how much they should send, the hash value would be different and everyone could detect that something has changed.&lt;/p&gt;

&lt;p&gt;The hash value of the previous block is used to calculate the hash value of the current block, creating a link between the blocks.&lt;/p&gt;

&lt;p&gt;Examples of algorithms with a link to their hash implementations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://rosettacode.org/wiki/SHA-1" rel="noopener noreferrer"&gt;SHA-1&lt;/a&gt;; insecure&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://rosettacode.org/wiki/SHA-256" rel="noopener noreferrer"&gt;SHA-256&lt;/a&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://rosettacode.org/wiki/MD5" rel="noopener noreferrer"&gt;MD5&lt;/a&gt;; insecure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keeping your passwords in the database using hash is a good practice (at the moment we can say that it is mandatory) in case when your database is exposed by a cracker, he can not have direct access to the password of yours customers.&lt;br&gt;&lt;br&gt;
So just create a hash for my password and problem solved? Not totally.&lt;/p&gt;

&lt;h3&gt;
  
  
  How hashes are broken
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/1230rTAtEjLyLu/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/1230rTAtEjLyLu/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By the properties of hash, we have seen that given a hash H(x) should not be computationally feasible to discover the input x, so it is not possible to “decrypt” the hash, after all it is an operation that does not allow return.&lt;/p&gt;

&lt;p&gt;But we know that given an input always the same hash is generated, and the crackers know that too. Then there are some known hash attacks for passwords:&lt;/p&gt;

&lt;h4&gt;
  
  
  Dictionary attacks and brute force
&lt;/h4&gt;

&lt;p&gt;The simplest way to try to find a hash.&lt;/p&gt;

&lt;p&gt;A dictionary attack uses a file containing words, phrases, common passwords, and so on to calculate the hash of each and check to see if it hits any of the list or database.&lt;/p&gt;

&lt;p&gt;The brute-force attack tests all word possibilities with a defined number of characters and verifies that the hash calculation is equal to some of the list.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Lookup Tables&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;Lookup table is an extremely effective method to break multiple hashes quickly. The general idea is to pre-compute the password hashes of a dictionary and save this value with its corresponding password. A good implementation of a lookup table can process hundreds of hashes per second, and contain billions of hashes.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Reverse Lookup Tables&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;This attack allows an attacker to apply a dictionary or brute-force attack to multiple hashes at the same time.&lt;/p&gt;

&lt;p&gt;First, the attacker creates a lookup table that maps each password hash of the database contracts to a list of users who have that hash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F721%2F1%2AlS8fY6ly3mvrHLUMHMcGlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F721%2F1%2AlS8fY6ly3mvrHLUMHMcGlw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The attacker then makes a dictionary attack or brute force, and upon discovering a password he already has a list of users who have it. This attack is very effective because it is common for many users to have the same password.&lt;/p&gt;

&lt;h4&gt;
  
  
  Rainbow tables
&lt;/h4&gt;

&lt;p&gt;One &lt;strong&gt;&lt;em&gt;rainbow table&lt;/em&gt;&lt;/strong&gt; is a pre-calculated hash lookup table. It is a practical example of the &lt;a href="https://en.wikipedia.org/wiki/Time/memory/data_tradeoff_attack" rel="noopener noreferrer"&gt;&lt;em&gt;Time/memory/data tradeoff attack&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It looks like the lookup table, except that it sacrifices the speed of breaking the hash to make the tables smaller. Because they are smaller, solutions for more hashes can be stored with the same space, being more effective in terms of storage.&lt;/p&gt;

&lt;p&gt;Then, exemplifying&lt;br&gt;&lt;br&gt;
We have a client that has the password 123456 and that is stored using the SHA-1 algorithm, so in the bank will have the hash 7c4a8d09ca3762af61e59520943dc26494f8941b&lt;/p&gt;

&lt;p&gt;When the cracker is in possession of this hash, he can just use a website or some specific program, which will test if it has this hash in the database and returns the value that generated it. As for example the &lt;a href="http://md5decrypt.net/en/Sha1/#answer" rel="noopener noreferrer"&gt;http://md5decrypt.net/en/Sha1/#answer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AERrzhfm0bYdNmA7nNIzgUQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AERrzhfm0bYdNmA7nNIzgUQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The list of 100 most used passwords is probably already in all possible hash banks, so there are campaigns to use increasingly difficult passwords to make these hashed banks difficult. But even with these issues, users do not want to have the problem of using more complex passwords, so as a developer, knowing these attacks, what is the best solution to this problem? Put more “salt” in your hash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/12Oy8aAs0CbTgY/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/12Oy8aAs0CbTgY/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Salt and Security Deployments
&lt;/h3&gt;

&lt;p&gt;The concept of salt, is to put some additional information in the password to add complexity when calculating the hash, for example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F934%2F1%2AbKVK5-5jmYo7N9QdQyFSHA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F934%2F1%2AbKVK5-5jmYo7N9QdQyFSHA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Placing additional information in the password makes it more difficult to create a lookup table.&lt;/p&gt;

&lt;h3&gt;
  
  
  What to avoid when using salt
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Reuse the salt
&lt;/h4&gt;

&lt;p&gt;Even being a hardcoded salt in the program, or once generated randomly. It is ineffective because if two users have the same password, they will have the same hash. With reverse lookup table attack, a brute force attack could be applied by simply testing the possibilities of salt and once found the salt, all your passwords are vulnerable.&lt;/p&gt;

&lt;h4&gt;
  
  
  Using short salt
&lt;/h4&gt;

&lt;p&gt;If your salt is too short, an attacker can build a lookup table for all possible salts. For example, if you use three ASCII characters, then you have only 857,375 possible salts. And that for computational terms is not much, if each lookup table contains only 1MB of the most common passwords, generating them would be an 837GB, and already have 1TB HD costing 50 dollars today, and it is a very cheap investment compared to the damage in the system.&lt;/p&gt;

&lt;h4&gt;
  
  
  Use username as salt
&lt;/h4&gt;

&lt;p&gt;Although they should be unique in the system, they are usually used by other accounts in other services. An attacker could make the user-password relationship and create lookup tables and break hash that has username as a salt.&lt;/p&gt;

&lt;p&gt;To be computationally impossible to create a lookup table for each possible salt, the salt should be long. A good rule is to use a salt that has the same size of the the hash function output, the SHA-256 output is 256 bits (32 bytes), so the salt should have at least 32 random numbers.&lt;/p&gt;

&lt;p&gt;Realize that the salt does not have to be a secret, it should only help avoid the attacks that I listed. I particularly like to use the timestamp hash of the time that the password has been changed, so I leave all the properties satisfied and I use the date in the format that I defined, making the task of generating a lookup table even more difficult.&lt;/p&gt;

</description>
      <category>security</category>
      <category>crypto</category>
      <category>cryptography</category>
      <category>hash</category>
    </item>
    <item>
      <title>Why  RSA Criptography works?</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Tue, 13 Nov 2018 23:42:04 +0000</pubDate>
      <link>https://dev.to/pemtajo/why-rsa-criptography-works-5g7a</link>
      <guid>https://dev.to/pemtajo/why-rsa-criptography-works-5g7a</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pJGLLk7S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AY3_lZTDC3ARsNpGSbyg0Pg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pJGLLk7S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AY3_lZTDC3ARsNpGSbyg0Pg.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s much easier to multiply numbers together than to factor them apart. That’s the basics of RSA encryption.&lt;/p&gt;

&lt;p&gt;In particular, the RSA encryption works with two large primes &lt;em&gt;p&lt;/em&gt; and &lt;em&gt;q&lt;/em&gt;, is quickly and easy to find the product &lt;em&gt;pq&lt;/em&gt; but it is harder to recover the factors &lt;em&gt;p&lt;/em&gt; and &lt;em&gt;q&lt;/em&gt; from &lt;em&gt;n&lt;/em&gt;. Generally &lt;em&gt;p&lt;/em&gt; and &lt;em&gt;q&lt;/em&gt; are numbers with hundreds of digits, factoring a number of this magnitude is very slow.&lt;/p&gt;

&lt;h3&gt;
  
  
  The algorithm
&lt;/h3&gt;

&lt;p&gt;To encode the message we need &lt;em&gt;n = pq&lt;/em&gt; and a positive integer &lt;em&gt;e&lt;/em&gt; that&lt;br&gt;&lt;br&gt;
be reversible module φ (n). &lt;a href="https://dev.to/pemtajo/euler-fermat-and-primality-test-2dc8"&gt;We talk about the Euler’s totient function before.&lt;/a&gt;&lt;br&gt;&lt;br&gt;
We will call the &lt;strong&gt;encoding key&lt;/strong&gt; pair &lt;em&gt;(n, e)&lt;/em&gt; of the RSA system. We will encode each message block separately and the final message will be the coded blocks sequence.&lt;br&gt;&lt;br&gt;
Important: Blocks already encoded can not be assembled to form a new number. This should make decoding impossible, as we’ll see later!&lt;br&gt;&lt;br&gt;
Let’s now show how to encode each block &lt;em&gt;b&lt;/em&gt;. We will call the coded block of &lt;em&gt;C(b)&lt;/em&gt;. First, remember that &lt;em&gt;b&lt;/em&gt; is an integer smaller than &lt;em&gt;n&lt;/em&gt;. We calculate &lt;em&gt;C(b)&lt;/em&gt; as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mlM2teNy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/198/1%2A4zDFCGccZ8DMo1umjGetXg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mlM2teNy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/198/1%2A4zDFCGccZ8DMo1umjGetXg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;where &lt;em&gt;0≤C (b) &amp;lt;n&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
Let’s see how to decode a block of the encoded message. The information we need to be able to decode consists of two numbers: &lt;em&gt;n&lt;/em&gt; and the inverse of &lt;em&gt;e&lt;/em&gt; module &lt;em&gt;φ(n)&lt;/em&gt;, which we denote &lt;em&gt;d&lt;/em&gt;. We will call the pair &lt;em&gt;(n, d)&lt;/em&gt; of &lt;strong&gt;decode key.&lt;/strong&gt; Be the one block of the message encoded. Then &lt;em&gt;D(a)&lt;/em&gt; will be the result of the decoding process. The way to calculate &lt;em&gt;D(a)&lt;/em&gt; is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kTe5zyKa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/212/1%2Apx6aU2jIUGYE5TpsUQfKhQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kTe5zyKa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/212/1%2Apx6aU2jIUGYE5TpsUQfKhQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;where &lt;em&gt;0 ≤ D (a) &amp;lt;n.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
First, it is very easy to calculate &lt;em&gt;d&lt;/em&gt;, if we have &lt;em&gt;φ(n)&lt;/em&gt; and &lt;em&gt;e&lt;/em&gt; : simply apply the extended Euclidean algorithm. On the other hand, it is clear that if &lt;em&gt;b&lt;/em&gt; is a block of the original message, then we expect &lt;em&gt;D(C(b)) = b&lt;/em&gt;, otherwise we will not have a useful code.&lt;br&gt;&lt;br&gt;
Finally, since the beginning of the notes we have been insisting that we encode using &lt;em&gt;n&lt;/em&gt; and decode using &lt;em&gt;p&lt;/em&gt; and &lt;em&gt;q&lt;/em&gt;; so you need to factor &lt;em&gt;n&lt;/em&gt; to decode. At this point we see that is not strictly true. In addition to the &lt;em&gt;n&lt;/em&gt; itself, we only need to know the inverse &lt;em&gt;d&lt;/em&gt; of &lt;em&gt;e&lt;/em&gt; modulo &lt;em&gt;φ(n)&lt;/em&gt; to decode. It turns out that we only know how to calculate &lt;em&gt;d&lt;/em&gt; by applying the extended algorithm to &lt;em&gt;e&lt;/em&gt; and &lt;em&gt;φ(n)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/hyPsnhMnltMhq/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/hyPsnhMnltMhq/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Proof that RSA works
&lt;/h3&gt;

&lt;p&gt;The obvious question which now arises is: &lt;em&gt;D(C(b)) = b&lt;/em&gt;?&lt;br&gt;&lt;br&gt;
That is, by decoding a coded message block, can we find a block of the original message? Because otherwise all our effort was meaningless …&lt;br&gt;&lt;br&gt;
Consider then &lt;em&gt;n = pq&lt;/em&gt;. We will prove that &lt;em&gt;D(C(b)) ≡ b mod (n)&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
How &lt;em&gt;1≤ b, D (C (b)) ≤ n-1&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;By definition, we have:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYXK5Umz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/335/1%2ASYMXQkVQAvE7ZIrnsrKljQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYXK5Umz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/335/1%2ASYMXQkVQAvE7ZIrnsrKljQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But &lt;em&gt;d&lt;/em&gt; is the inverse of &lt;em&gt;e&lt;/em&gt; module &lt;em&gt;φ(n)&lt;/em&gt;. Then there is an integer &lt;em&gt;k&lt;/em&gt; such that &lt;em&gt;ed=1 + kφ (n).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Soon,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_Jz5NRPt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/282/1%2Ao_rMOeSCjobzqpDrqgH47Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_Jz5NRPt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/282/1%2Ao_rMOeSCjobzqpDrqgH47Q.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If &lt;em&gt;b&lt;/em&gt; and &lt;em&gt;n&lt;/em&gt; are relatives primes, then we can use &lt;a href="https://dev.to/pemtajo/euler-fermat-and-primality-test-2dc8"&gt;Euler’s Theorem&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wl3I1LTl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/313/1%2AVBny99LCYz9khl8KHta3Cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wl3I1LTl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/313/1%2AVBny99LCYz9khl8KHta3Cw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose that &lt;em&gt;b&lt;/em&gt; and &lt;em&gt;n&lt;/em&gt; are not prime to each other. Since &lt;em&gt;n = pq&lt;/em&gt;, &lt;em&gt;p&lt;/em&gt; and &lt;em&gt;q&lt;/em&gt; are distinct primes, then &lt;em&gt;φ(n) = (p-1)(q-1)&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
Soon,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q838YBWS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/215/1%2AzIXL3s2Xuv69nQ9K0PXk8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q838YBWS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/215/1%2AzIXL3s2Xuv69nQ9K0PXk8g.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If &lt;em&gt;b&lt;/em&gt; and &lt;em&gt;p&lt;/em&gt; are relative prime, then we can use Fermat’s Theorem, and we have bᵖ⁻¹ ≡ 1 mod (p).&lt;br&gt;&lt;br&gt;
Therefore, &lt;em&gt;bᵉᵈ ≡ b mod (p)&lt;/em&gt;, whichever is &lt;em&gt;b&lt;/em&gt;.&lt;br&gt;&lt;br&gt;
We do the same for prime q, we get, &lt;em&gt;bᵉᵈ ≡ b mod (q).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Therefore,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---TOEF31x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/196/1%2AM-3_xtH9Jv4B8iC72TYrqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---TOEF31x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/196/1%2AM-3_xtH9Jv4B8iC72TYrqw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;as we wanted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;As an developer I have a necessary to put code in everywhere, even when don’t need it, so I will put here a simple implementation of this algorithm, and that can be useful later&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qE8T4Dy5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AzL2la0u4YBEtTofwqbDBtw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qE8T4Dy5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AzL2la0u4YBEtTofwqbDBtw.png" alt=""&gt;&lt;/a&gt;The code is &lt;a href="https://github.com/pmdragon/scripts/blob/master/rsa.py"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>proofofconcept</category>
      <category>crypto</category>
      <category>mathematics</category>
      <category>python</category>
    </item>
    <item>
      <title>Euler, Fermat and Primality Test</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Sat, 10 Nov 2018 21:04:33 +0000</pubDate>
      <link>https://dev.to/pemtajo/euler-fermat-and-primality-test-2dc8</link>
      <guid>https://dev.to/pemtajo/euler-fermat-and-primality-test-2dc8</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FQVk4y4---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2AgyD2i1OZWaKSDWB6rj8nFw.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FQVk4y4---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2AgyD2i1OZWaKSDWB6rj8nFw.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In number theory, The &lt;strong&gt;Euler’s totient function&lt;/strong&gt; , counts the number of positive integers less than m and relatively prime to &lt;em&gt;m&lt;/em&gt;. For a prime number &lt;em&gt;p&lt;/em&gt;, &lt;em&gt;φ(p) = p-1&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It can be defined more formally as the number of integers &lt;em&gt;k&lt;/em&gt; in the range &lt;em&gt;1 ≤ k ≤ n&lt;/em&gt; for which the greatest common divisor &lt;em&gt;gcd(n, k)&lt;/em&gt; is equal to 1.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is &lt;strong&gt;Fermat’s little theorem&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Fermat's_little_theorem"&gt;&lt;strong&gt;Fermat’s little theorem&lt;/strong&gt;&lt;/a&gt; says that if &lt;em&gt;p&lt;/em&gt; is a prime and &lt;em&gt;a&lt;/em&gt; is not a multiple of &lt;em&gt;p&lt;/em&gt;, then&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LtrNR985--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/173/1%2ACotGjw6Dd51xqzfvJvSNFA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LtrNR985--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/173/1%2ACotGjw6Dd51xqzfvJvSNFA.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Euler’s generalization&lt;/strong&gt; of Fermat’s little theorem says that if &lt;em&gt;a&lt;/em&gt; is relatively prime to &lt;em&gt;m&lt;/em&gt;, then&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kNKHflHD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/225/1%2ABPy80qeKAXp309Edp0qolA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kNKHflHD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/225/1%2ABPy80qeKAXp309Edp0qolA.jpeg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Euler’s totient function is &lt;strong&gt;multiplicative&lt;/strong&gt; , that is, if &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt; are relatively prime, then φ(&lt;em&gt;ab&lt;/em&gt;) = φ(&lt;em&gt;a&lt;/em&gt;) φ(&lt;em&gt;b&lt;/em&gt;). We will use this fact in other discuss.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  The Proof of generalization
&lt;/h3&gt;

&lt;p&gt;Be &lt;em&gt;r=φ(n)&lt;/em&gt; and &lt;em&gt;b₀, b₁, …, bᵣ,&lt;/em&gt; integers numbers, primes relative two at two, and all prime relative with &lt;em&gt;n&lt;/em&gt;. So &lt;em&gt;ab₀, ab₁, …, abᵣ,&lt;/em&gt; still congruent &lt;em&gt;mod(n)&lt;/em&gt; for&lt;br&gt;&lt;br&gt;
&lt;em&gt;i=1,2, …,r.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The collection &lt;em&gt;b₀, b₁, …, bᵣ&lt;/em&gt; and &lt;em&gt;ab₀, ab₁, …, abᵣ&lt;/em&gt; are equals &lt;em&gt;mod(n)&lt;/em&gt;. So let multiplity all&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lTVNJ5Es--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/279/1%2A2nRFSnPCtON2oJT0g7jawQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lTVNJ5Es--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/279/1%2A2nRFSnPCtON2oJT0g7jawQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YmAEE7MO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/493/1%2AR5O59TzgeqQVCMkcx2roAQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YmAEE7MO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/493/1%2AR5O59TzgeqQVCMkcx2roAQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In anyway, &lt;em&gt;(aʳ-1) ≡ 0 (mod n)&lt;/em&gt; and how &lt;em&gt;aʳ ≡ 1(mod n)&lt;/em&gt; and&lt;br&gt;&lt;br&gt;
&lt;em&gt;r=φ(n)&lt;/em&gt;, then&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CfFBTPbL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/255/1%2AOk_DVBZh52E-ES2yp3AOgQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CfFBTPbL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/255/1%2AOk_DVBZh52E-ES2yp3AOgQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Primality testing
&lt;/h3&gt;

&lt;p&gt;One best things about this theorem is the primality testing.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;contrapositive&lt;/strong&gt; of Fermat’s little theorem is useful: if the congruence &lt;em&gt;a&lt;/em&gt;ᵖ⁻¹&lt;em&gt;≡&lt;/em&gt; 1 (mod &lt;em&gt;p&lt;/em&gt;) does &lt;em&gt;not&lt;/em&gt; true, then either &lt;em&gt;p&lt;/em&gt; is &lt;em&gt;not&lt;/em&gt; prime or &lt;em&gt;a&lt;/em&gt; is a multiple of &lt;em&gt;p&lt;/em&gt;. In practice, &lt;em&gt;a&lt;/em&gt; is much smaller than &lt;em&gt;p&lt;/em&gt;, and so one can conclude that &lt;em&gt;p&lt;/em&gt; is not prime.&lt;/p&gt;

&lt;p&gt;Technically this is a test for non-primality: it can only prove that a number is not prime. For example, if 2ᵖ⁻¹ ≢ 1 (mod &lt;em&gt;p&lt;/em&gt;) then we know &lt;em&gt;p&lt;/em&gt; is not a prime. But if 2ᵖ⁻¹ &lt;em&gt;≡&lt;/em&gt; 1 (mod &lt;em&gt;p&lt;/em&gt;) then all we know is that we haven’t failed the test; we don’t have certain if that &lt;em&gt;p&lt;/em&gt; is prime or not. So we try another value of &lt;em&gt;a&lt;/em&gt;, for example 5, and see if 5ᵖ⁻¹ &lt;em&gt;≡&lt;/em&gt; 1 (mod &lt;em&gt;p&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;In theory looks perfect, so all the crypto theory was ruined? Of course, not, because even easy to undestand, looking in thecomputacionais terms, this is problematic, for example, for a small number like 223, and for &lt;em&gt;a&lt;/em&gt; with value of 2, we have;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4I8LMD3Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/406/1%2Al1R6OLprvEaE8bu_C-Ulrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4I8LMD3Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/406/1%2Al1R6OLprvEaE8bu_C-Ulrw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We know that 223 is prime, but 2²²³ is hard to compute even in robusts computers, so numbers like 2321412341243123423413263466567678352323 is harder to determine, but all the theory is usefull, with many implications in criptography and number theory. I will discuss this in other posts.&lt;/p&gt;

</description>
      <category>primenumbers</category>
      <category>cryptography</category>
      <category>mathematics</category>
    </item>
    <item>
      <title>Tips for working with shell scripts</title>
      <dc:creator>Pedro Matias de Araujo</dc:creator>
      <pubDate>Tue, 28 Aug 2018 01:13:29 +0000</pubDate>
      <link>https://dev.to/pemtajo/tips-for-working-with-bash-scripts-3mk3</link>
      <guid>https://dev.to/pemtajo/tips-for-working-with-bash-scripts-3mk3</guid>
      <description>&lt;p&gt;Years ago I was programming for a small company who worked with &lt;em&gt;boarded system&lt;/em&gt;. There I wrote codes for &lt;em&gt;shell scripts&lt;/em&gt;, &lt;em&gt;python scripts&lt;/em&gt; and another codes for &lt;em&gt;boarded systems&lt;/em&gt;, sometimes for clients who lived in another state with machines that I don’t had any access, so my scripts were always a &lt;em&gt;black box&lt;/em&gt; and for that was very common send the updates for e-mail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/nkLB4Gp8H6hFe/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/nkLB4Gp8H6hFe/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefor, the client sended me a e-mail with the subject: “Not working”. In 5 minutes I refreshed the file and sended back. Problem solved right? Not totally.&lt;/p&gt;

&lt;p&gt;It’s hard to small companies, even freelancers, do a good logistic to work with bash scripts because the client do not can wait and you have to do something to solve the problem, so the “add this line” always win against a robust process.&lt;/p&gt;

&lt;p&gt;After a lot of problems, with developer and freelancer, I want to share good advices for work with &lt;em&gt;sh files&lt;/em&gt; (maybe can be usefull for another scripts)&lt;/p&gt;

&lt;p&gt;It’s simple tips, but the bugs (and headache) is in the details:&lt;/p&gt;

&lt;h4&gt;
  
  
  Write all in functions (isolated if possible)
&lt;/h4&gt;

&lt;p&gt;Do your logic fragmented, will help when need change and recicly your code.&lt;/p&gt;

&lt;p&gt;Do a scope for each function support you to change the logic without bugs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Always pick the file on the master
&lt;/h4&gt;

&lt;p&gt;It’s obvious, I know, but in real world, change your file for send to your client without commit before is faster, and in a busy day, you can forget to do this commit later, so you have one file in your git and another with your client. It’s not hard to imagine catastrophics scenarios.&lt;/p&gt;

&lt;h4&gt;
  
  
  Always create branchs for work
&lt;/h4&gt;

&lt;p&gt;That tip is usually for teams, but work well for freela too and helps to do not commit direct in master as well as avoid bugs without revision and “commit for commit”.&lt;/p&gt;

&lt;h4&gt;
  
  
  Comment on shell script
&lt;/h4&gt;

&lt;p&gt;It’s an eternal discussion about comment your code or not, in other languages I believe is not necessary, but how in &lt;em&gt;bash&lt;/em&gt; sometimes is not intuitive, like I’m a practical developer, I prefer comment my &lt;em&gt;bash scripts&lt;/em&gt;, in the end this save my time.&lt;/p&gt;

&lt;h4&gt;
  
  
  Do tests
&lt;/h4&gt;

&lt;p&gt;Yes, do test in bash scripts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3o6Mbbs879ozZ9Yic0/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3o6Mbbs879ozZ9Yic0/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This tests don’t need be a unit test, but can be a functional tests, for example.&lt;br&gt;&lt;br&gt;
If your script move a file to another folder, you can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create a file in the original folder&lt;/li&gt;
&lt;li&gt;run script&lt;/li&gt;
&lt;li&gt;do assert that file is in the destiny folder, and not in the origin&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With tests, is easy to see fool mistakes. Do the test in bash is hard sometimes, so use another language for this, Python is a good call and is my preference.&lt;/p&gt;

&lt;h4&gt;
  
  
  Do a log
&lt;/h4&gt;

&lt;p&gt;And finally the golden tip. One good log, will help to identify the errors faster, and it’s usefull to see all activity and performance, like find bugs and system bottlenecks. It’s easy do log in bash files, so is not have a reason to do not do one.&lt;/p&gt;

&lt;p&gt;This is my tips to do a process with less bugs and fatal errors.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>linux</category>
      <category>script</category>
      <category>git</category>
    </item>
  </channel>
</rss>
