Block chain js to skrypt zabezpieczający komunikację między użytkownikiem, a serwerem.
Skrypt szyfruje wpisane dane z formularza po stronie użytkownika i przesyła w postaci zaszyfrowanych bloków na serwer.
Pamiętaj aby dokonać odpowiednich modyfikacji kodu dostosowując formularz html do skryptu js.
Formularz html
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>blockchain.js sample form</title>
<div><a href="/">main page</a></div>
select the level of blockchain dispersion
<select id="level" name="level" style="display:block;width:100%;margin:3px;">
<option value="">select level</opiton>
<option value="0">all in get</option>
<option value="1">chain in cookie, blocks in get</option>
</select>
type a chain, should contain all string elements, unless you don't want to
<input id="net" type="text" name="net" placeholder="default chain random: 1234567890" style="display:block;width:100%;margin:3px;">
type a string, should contain all chain elements, unless you don't want to
<input id="text" type="text" name="text" placeholder="default string: 127001 (max length of 31 elements without breaks)" style="display:block;width:100%;margin:3px;">
destynation ip, recommends ip is your ip
<input id="ip" type="text" name="ip" placeholder="ip: 127.0.0.1 - this only for chain in cookie level option selected" style="display:block;width:100%;margin:3px;">
if you are ready
<button onclick="blockchain();" style="cursor:pointer;display:block;width:100%;margin:3px;">GENERATE BLOCKCHAIN JS</button>
<a href="sample.html">clean form</a>
<div style="word-break:break-all;">
without any changes in form, the blockchain js generator use the following data
<br />
1234567890 łańcuch
<br />
127001 dowolny ciąg znaków
<br />
127.0.0.1 ip
</div>
<script src="blockchain.js"></script>
Skrypt js.
W skrypcie znajduje się lokalny standardowy dres ip 127.0.0.1 oraz 127001 na wypadek braku wpisu, oczywiście można zastąpić własnym.
function blockchain()
{
if(document.getElementById("ip"))
{
var ip = document.getElementById("ip").value;
if(ip=="")
{
var ip = "127.0.0.1";
}
}
else
{
var ip = "127.0.0.1";
}
if(document.getElementById("net"))
{
var net = document.getElementById("net").value;
if(net=="")
{
var net = "1234567890";
}
else
{
var net_value = document.getElementById("net").value;
}
}
else
{
var net = "1234567890";
}
if(document.getElementById("text"))
{
var text = document.getElementById("text").value;
if(text=="")
{
var text = "127001";
}
}
else
{
var text = "127001";
}
if(document.getElementById("level"))
{
var level = document.getElementById("level").value;
if(level=="")
{
var level = 0;
}
}
else
{
var level = 0;
}
var entry = text;
var redirect = "http://"+ip+"/?"
if(typeof entry !== "undefined")
{
var entry_split = entry.split("");
if(net)
{
var net_split = net.split("");
var net_split_shuffled = net_split
.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value)
var net_join = net_split_shuffled.join("");
}
if(net_value)
{
var net_split = net_value.split("");
var net_split_shuffled = net_value.split("");
var net_join = net_value;
}
function get_block(entry_Array)
{
const net_array = entry_Array[0]
const entry_array = entry_Array[1]
const block_array = [];
entry_array.forEach((entry_element ,entry_entry_no) =>
{
net_array.forEach((net_element,net_entry_no) =>
{
if (entry_element === net_element)
{
const block_no = net_entry_no;
block_array.push(block_no);
}
})
})
return block_array;
}
const block = get_block([net_split_shuffled, entry_split]);
const block_join = block.join("");
function bit_leght()
{
const block_array = block
const bit_Array = [];
block_array.forEach((block_element) =>
{
const string_block_element = block_element.toString();
const length_string_block_element = string_block_element.length;
bit_Array.push(length_string_block_element);
})
return bit_Array;
}
const bits = bit_leght();
const bits_join = bits.join("");
function get_bit_block()
{
const bit_array = bits
const bit_block_array = [];
bit_array.forEach((bits_element) =>
{
if(bits_element===2)
{
const par = "24680";
const PAR = par.split("");
const PAR_shuffled = PAR
.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value);
const par_no = PAR_shuffled[bits_element];
const replace_par_no = par_no.replace(bits_element, par_no);
bit_block_array.push(replace_par_no);
}
else
{
const npar = "13579";
const NPAR = npar.split("");
const NPAR_shuffled = NPAR
.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value);
const npar_no = NPAR_shuffled[bits_element];
const replace_npar_no = npar_no.replace(bits_element, npar_no);
bit_block_array.push(replace_npar_no);
}
})
return bit_block_array;
}
const bit_block = get_bit_block();
const bit_block_join = bit_block.join("");
if(level==0)
{
var blockchain = block_join + "=" + bit_block_join + "&" + net_join;
}
if(level==1)
{
var btoa_net_join = "";
document.cookie = "btoa_net_join" + "=" + net_join + ";expires=" + 0
+ ";domain=" + ip + ";path=/";
var blockchain = block_join +"=" + bit_block_join;
}
//const btoa_blockchain = btoa(blockchain);
//const request_uri = btoa_net_join + btoa_blockchain;
//const btoa_request_uri = btoa(request_uri);
//const replace_btoa_request_uri = btoa_request_uri.replace("=","");
//const replace_btoa_request_uri_link = replace_btoa_request_uri.replace("=","");
window.location = redirect + blockchain;
//console.log(net_join);
//console.log(blockchain);
//console.log(redirect + blockchain);
}
}
© created by Damian Pacanowski
Komentarze
Prześlij komentarz