Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.2;
- contract c1{
- function address2String(address _add) external pure returns (string memory){
- bytes32 value = bytes32(uint256(_add));
- bytes memory letter = "0123456789abcdef";
- bytes memory s = new bytes(40);
- for (uint i = 0; i < 20; i++) {
- s[i*2] = letter[uint(uint8(value[i + 12] >> 4))];
- s[1+i*2] = letter[uint(uint8(value[i + 12] & 0x0f))];
- }
- return string(s);
- }
- }
- contract c2{
- function bytes32ToBytes(bytes32 value) internal pure returns (string memory) {
- //bytes32 value = bytes32(uint256(data));
- bytes memory letter = "0123456789abcdef";
- bytes memory s = new bytes(40);
- for (uint i = 0; i < 20; i++) {
- s[i*2] = letter[uint(uint8(value[i + 12] >> 4))];
- s[1+i*2] = letter[uint(uint8(value[i + 12] & 0x0f))];
- }
- return string(s);
- }
- function getAddress() public returns (bytes memory,bytes32, bytes memory ,string memory,string memory){
- string memory _ad;
- c1 x = new c1();
- _ad = x.address2String(address(this));
- string memory _add = "dc04977a2078c8ffdf086d618d1f961b6c546222";
- bytes memory b = bytes(_add);
- bytes memory res = new bytes(40);
- bytes32 hash1 = keccak256(bytes(_add));
- string memory st_hash = bytes32ToBytes(hash1);
- bytes memory hash = bytes(st_hash);
- for (uint i=0;i<res.length;i++){
- if(uint8(b[i])>96 && uint8(b[i])<103){
- if (uint8(hash[i])>56) res[i] = byte(uint8(b[i])-32);
- else res[i] = b[i];
- //res[i] = 'x';
- }
- else res[i] = b[i];
- }
- return (b, hash1, hash, _add , string(res));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement