<?php
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../includes/functions.php';

$page_title   = 'Hash Generator – MD5, SHA-1, SHA-256 and more';
$page_desc    = 'Free hash generator: create MD5, SHA-1, SHA-256, SHA-512 and other hashes from any text – instantly in your browser on ipcheck.tools.';
$page_current = 'hash';

require_once __DIR__ . '/header.php';
?>

<div class="hero">
  <div class="hero-label">Tool</div>
  <div class="hero-title">Hash Generator</div>
  <div class="hero-sub">Generate MD5, SHA-1, SHA-256, SHA-512 and more from any text</div>
</div>

<div class="wrap">

  <div class="ad-slot"><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-8287576653347400" data-ad-slot="2715725452" data-ad-format="auto" data-full-width-responsive="true"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>

  <div class="card card-blue">
    <div class="card-title"><i class="ti ti-hash"></i> Input</div>
    <textarea id="input-text"
      style="width:100%; background:var(--bg3); border:1px solid #2d3a52; border-radius:7px; padding:12px 14px; font-size:13px; color:var(--text); font-family:var(--font-mono); outline:none; resize:vertical; min-height:100px;"
      placeholder="Enter text to hash..."
      oninput="generateHashes()"></textarea>
    <div style="display:flex; gap:8px; margin-top:12px; flex-wrap:wrap;">
      <button class="copy-btn" onclick="clearInput()" style="margin-top:0; background:#1a1a2a; border-color:#2a2a3a; color:var(--text3);">
        <i class="ti ti-trash"></i> Clear
      </button>
    </div>
  </div>

  <div class="card" id="results-card" style="display:none;">
    <div class="card-title"><i class="ti ti-list"></i> Hash values</div>
    <div id="hash-results"></div>
  </div>

  <div class="card">
    <div class="card-title"><i class="ti ti-info-circle"></i> Hash algorithms</div>
    <div class="data-row"><span class="dk">MD5</span><span class="dv" style="font-size:12px;">128-bit · fast · not recommended for security</span></div>
    <div class="data-row"><span class="dk">SHA-1</span><span class="dv" style="font-size:12px;">160-bit · deprecated · avoid for security</span></div>
    <div class="data-row"><span class="dk">SHA-256</span><span class="dv" style="font-size:12px; color:var(--green);">256-bit · secure · recommended</span></div>
    <div class="data-row"><span class="dk">SHA-512</span><span class="dv" style="font-size:12px; color:var(--green);">512-bit · very secure · recommended</span></div>
    <div class="data-row"><span class="dk">SHA-384</span><span class="dv" style="font-size:12px;">384-bit · secure</span></div>
  </div>

  <div class="ad-slot"><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-8287576653347400" data-ad-slot="2715725452" data-ad-format="auto" data-full-width-responsive="true"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>

  <div class="tools-row">
    <a href="/en/"           class="tool-btn"><i class="ti ti-home"></i><span>My IP</span></a>
    <a href="/en/hash.php"   class="tool-btn current"><i class="ti ti-hash"></i><span>Hash</span></a>
    <a href="/en/base64.php" class="tool-btn"><i class="ti ti-code"></i><span>Base64</span></a>
    <a href="/en/url-encoder.php" class="tool-btn"><i class="ti ti-link"></i><span>URL Encoder</span></a>
    <a href="/en/passwort.php" class="tool-btn"><i class="ti ti-lock-password"></i><span>Password</span></a>
  </div>

  <div class="seo-box">
    <h2>What is a hash?</h2>
    <p>A hash function converts input data of any length into a fixed-length output (the hash value). Hash functions are one-way – you cannot reconstruct the original data from the hash. They are used to verify data integrity (checksums), store passwords securely and create digital signatures. <strong>SHA-256</strong> and <strong>SHA-512</strong> are the current recommended algorithms. MD5 and SHA-1 are considered insecure for cryptographic purposes but are still used for checksums.</p>
  </div>



<script>
async function generateHashes() {
  const input = document.getElementById('input-text').value;
  const card  = document.getElementById('results-card');
  const container = document.getElementById('hash-results');

  if (!input) { card.style.display = 'none'; return; }

  card.style.display = 'block';

  const algorithms = ['MD5', 'SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'];
  const subtleAlgos = {'SHA-1': 'SHA-1', 'SHA-256': 'SHA-256', 'SHA-384': 'SHA-384', 'SHA-512': 'SHA-512'};

  const encoder = new TextEncoder();
  const data    = encoder.encode(input);

  const hashes = {};

  // SHA via Web Crypto API
  for (const [name, algo] of Object.entries(subtleAlgos)) {
    try {
      const buf  = await crypto.subtle.digest(algo, data);
      const hex  = Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, '0')).join('');
      hashes[name] = hex;
    } catch(e) {
      hashes[name] = 'Not supported';
    }
  }

  // MD5 (simple implementation)
  hashes['MD5'] = md5(input);

  container.innerHTML = Object.entries(hashes).map(([name, h]) => `
    <div style="margin-bottom:12px; padding-bottom:12px; border-bottom:1px solid var(--border2);">
      <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:6px;">
        <span style="font-size:11px; color:var(--text4); letter-spacing:1px; text-transform:uppercase;">${name}</span>
        <button onclick="navigator.clipboard.writeText('${h}')" class="copy-btn" style="margin-top:0; font-size:11px; padding:3px 8px;">
          <i class="ti ti-copy"></i> Copy
        </button>
      </div>
      <div style="font-family:var(--font-mono); font-size:12px; color:var(--blue-dim); word-break:break-all; background:var(--bg3); padding:8px 10px; border-radius:6px;">${h}</div>
    </div>
  `).join('');
}

function clearInput() {
  document.getElementById('input-text').value = '';
  document.getElementById('results-card').style.display = 'none';
}

// Simple MD5 implementation
function md5(string) {
  function safeAdd(x,y){var lsw=(x&0xffff)+(y&0xffff);var msw=(x>>16)+(y>>16)+(lsw>>16);return(msw<<16)|(lsw&0xffff)}
  function bitRotateLeft(num,cnt){return(num<<cnt)|(num>>>(32-cnt))}
  function md5cmn(q,a,b,x,s,t){return safeAdd(bitRotateLeft(safeAdd(safeAdd(a,q),safeAdd(x,t)),s),b)}
  function md5ff(a,b,c,d,x,s,t){return md5cmn((b&c)|((~b)&d),a,b,x,s,t)}
  function md5gg(a,b,c,d,x,s,t){return md5cmn((b&d)|(c&(~d)),a,b,x,s,t)}
  function md5hh(a,b,c,d,x,s,t){return md5cmn(b^c^d,a,b,x,s,t)}
  function md5ii(a,b,c,d,x,s,t){return md5cmn(c^(b|(~d)),a,b,x,s,t)}
  var i,x=Array(),k,AA,BB,CC,DD,a,b,c,d,S11=7,S12=12,S13=17,S14=22,S21=5,S22=9,S23=14,S24=20,S31=4,S32=11,S33=16,S34=23,S41=6,S42=10,S43=15,S44=21;
  string=unescape(encodeURIComponent(string));
  var nblocks=Math.ceil((string.length+8)/64);
  for(i=0;i<nblocks*16;i++)x[i]=0;
  for(i=0;i<string.length;i++)x[i>>2]|=string.charCodeAt(i)<<((i%4)*8);
  x[i>>2]|=0x80<<((i%4)*8);x[nblocks*16-2]=string.length*8;
  a=1732584193;b=-271733879;c=-1732584194;d=271733878;
  for(i=0;i<x.length;i+=16){AA=a;BB=b;CC=c;DD=d;
  a=md5ff(a,b,c,d,x[i+0],S11,-680876936);d=md5ff(d,a,b,c,x[i+1],S12,-389564586);c=md5ff(c,d,a,b,x[i+2],S13,606105819);b=md5ff(b,c,d,a,x[i+3],S14,-1044525330);
  a=md5ff(a,b,c,d,x[i+4],S11,-176418897);d=md5ff(d,a,b,c,x[i+5],S12,1200080426);c=md5ff(c,d,a,b,x[i+6],S13,-1473231341);b=md5ff(b,c,d,a,x[i+7],S14,-45705983);
  a=md5ff(a,b,c,d,x[i+8],S11,1770035416);d=md5ff(d,a,b,c,x[i+9],S12,-1958414417);c=md5ff(c,d,a,b,x[i+10],S13,-42063);b=md5ff(b,c,d,a,x[i+11],S14,-1990404162);
  a=md5ff(a,b,c,d,x[i+12],S11,1804603682);d=md5ff(d,a,b,c,x[i+13],S12,-40341101);c=md5ff(c,d,a,b,x[i+14],S13,-1502002290);b=md5ff(b,c,d,a,x[i+15],S14,1236535329);
  a=md5gg(a,b,c,d,x[i+1],S21,-165796510);d=md5gg(d,a,b,c,x[i+6],S22,-1069501632);c=md5gg(c,d,a,b,x[i+11],S23,643717713);b=md5gg(b,c,d,a,x[i+0],S24,-373897302);
  a=md5gg(a,b,c,d,x[i+5],S21,-701558691);d=md5gg(d,a,b,c,x[i+10],S22,38016083);c=md5gg(c,d,a,b,x[i+15],S23,-660478335);b=md5gg(b,c,d,a,x[i+4],S24,-405537848);
  a=md5gg(a,b,c,d,x[i+9],S21,568446438);d=md5gg(d,a,b,c,x[i+14],S22,-1019803690);c=md5gg(c,d,a,b,x[i+3],S23,-187363961);b=md5gg(b,c,d,a,x[i+8],S24,1163531501);
  a=md5gg(a,b,c,d,x[i+13],S21,-1444681467);d=md5gg(d,a,b,c,x[i+2],S22,-51403784);c=md5gg(c,d,a,b,x[i+7],S23,1735328473);b=md5gg(b,c,d,a,x[i+12],S24,-1926607734);
  a=md5hh(a,b,c,d,x[i+5],S31,-378558);d=md5hh(d,a,b,c,x[i+8],S32,-2022574463);c=md5hh(c,d,a,b,x[i+11],S33,1839030562);b=md5hh(b,c,d,a,x[i+14],S34,-35309556);
  a=md5hh(a,b,c,d,x[i+1],S31,-1530992060);d=md5hh(d,a,b,c,x[i+4],S32,1272893353);c=md5hh(c,d,a,b,x[i+7],S33,-155497632);b=md5hh(b,c,d,a,x[i+10],S34,-1094730640);
  a=md5hh(a,b,c,d,x[i+13],S31,681279174);d=md5hh(d,a,b,c,x[i+0],S32,-358537222);c=md5hh(c,d,a,b,x[i+3],S33,-722521979);b=md5hh(b,c,d,a,x[i+6],S34,76029189);
  a=md5hh(a,b,c,d,x[i+9],S31,-640364487);d=md5hh(d,a,b,c,x[i+12],S32,-421815835);c=md5hh(c,d,a,b,x[i+15],S33,530742520);b=md5hh(b,c,d,a,x[i+2],S34,-995338651);
  a=md5ii(a,b,c,d,x[i+0],S41,-198630844);d=md5ii(d,a,b,c,x[i+7],S42,1126891415);c=md5ii(c,d,a,b,x[i+14],S43,-1416354905);b=md5ii(b,c,d,a,x[i+5],S44,-57434055);
  a=md5ii(a,b,c,d,x[i+12],S41,1700485571);d=md5ii(d,a,b,c,x[i+3],S42,-1894986606);c=md5ii(c,d,a,b,x[i+10],S43,-1051523);b=md5ii(b,c,d,a,x[i+1],S44,-2054922799);
  a=md5ii(a,b,c,d,x[i+8],S41,1873313359);d=md5ii(d,a,b,c,x[i+15],S42,-30611744);c=md5ii(c,d,a,b,x[i+6],S43,-1560198380);b=md5ii(b,c,d,a,x[i+13],S44,1309151649);
  a=md5ii(a,b,c,d,x[i+4],S41,-145523070);d=md5ii(d,a,b,c,x[i+11],S42,-1120210379);c=md5ii(c,d,a,b,x[i+2],S43,718787259);b=md5ii(b,c,d,a,x[i+9],S44,-343485551);
  a=safeAdd(a,AA);b=safeAdd(b,BB);c=safeAdd(c,CC);d=safeAdd(d,DD)}
  var output=Array(a,b,c,d);var hex='';for(i=0;i<4;i++){for(k=0;k<4;k++)hex+=(('0'+(output[i]>>>(k*8)&0xff).toString(16)).slice(-2))};return hex;
}
</script>

<?php require_once __DIR__ . '/footer.php'; ?>
