Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. pragma solidity ^0.5.2;
  2.  
  3. contract c1{
  4. function address2String(address _add) external pure returns (string memory){
  5. bytes32 value = bytes32(uint256(_add));
  6. bytes memory letter = "0123456789abcdef";
  7.  
  8. bytes memory s = new bytes(40);
  9. for (uint i = 0; i < 20; i++) {
  10. s[i*2] = letter[uint(uint8(value[i + 12] >> 4))];
  11. s[1+i*2] = letter[uint(uint8(value[i + 12] & 0x0f))];
  12. }
  13. return string(s);
  14. }
  15. }
  16.  
  17. contract c2{
  18.  
  19. function bytes32ToBytes(bytes32 value) internal pure returns (string memory) {
  20. //bytes32 value = bytes32(uint256(data));
  21. bytes memory letter = "0123456789abcdef";
  22.  
  23. bytes memory s = new bytes(40);
  24. for (uint i = 0; i < 20; i++) {
  25. s[i*2] = letter[uint(uint8(value[i + 12] >> 4))];
  26. s[1+i*2] = letter[uint(uint8(value[i + 12] & 0x0f))];
  27. }
  28. return string(s);
  29. }
  30.  
  31. function getAddress() public returns (bytes memory,bytes32, bytes memory ,string memory,string memory){
  32. string memory _ad;
  33. c1 x = new c1();
  34. _ad = x.address2String(address(this));
  35.  
  36. string memory _add = "dc04977a2078c8ffdf086d618d1f961b6c546222";
  37. bytes memory b = bytes(_add);
  38. bytes memory res = new bytes(40);
  39. bytes32 hash1 = keccak256(bytes(_add));
  40. string memory st_hash = bytes32ToBytes(hash1);
  41. bytes memory hash = bytes(st_hash);
  42.  
  43. for (uint i=0;i<res.length;i++){
  44. if(uint8(b[i])>96 && uint8(b[i])<103){
  45. if (uint8(hash[i])>56) res[i] = byte(uint8(b[i])-32);
  46. else res[i] = b[i];
  47. //res[i] = 'x';
  48. }
  49. else res[i] = b[i];
  50. }
  51. return (b, hash1, hash, _add , string(res));
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement