Can anyone please explain what a 51% attack
Not quickly or easily.
Miners assemble transactions into blocks and then perform hashing on the header of the block to establish a proof-of-work. The target value that establishes how difficult it is to find a valid hash is adjusted every 2016 blocks to make sure that with the combined hash power of the entire world it will take on average 10 minutes to successfully find a valid hash.
The chances of finding a successful hash for a block are directly proportional to the percentage of the hash power you have. So, if a miner or pool controls 10% of the global hash power (leaving 90% for the rest of the world), then that miner would find successful hashes 10% of the time (and the rest of the world would find successful hashes 90% of the time).
Every node and every miner agree to always build on top of the chain that has the most proof-of-work (which in typical cases means the chain with the most blocks). If a miner with less than the combined hash power of the entire world were to refuse to build on the longest chain, the whole world would simply ignore his blocks. He'd be wasting his time and money since he'd never receive a spendable block reward.
As that miner approaches 50% of the global hash power, the amount of hashing the rest of the world is doing falls towards 50% (since, obviously, the sum of that miner and the rest of the world must be 100%). At 50%, the miner (or pool) is producing just as much hash power as the rest of the world combined. They are finding half of the blocks and if they were to ignore all the blocks produced by everyone else their chain would grow at the same rate as the rest of the world's chain. In the long run, this isn't enough to get ahead and therefore limits what they can change.
Once a miner has more than 50% of the global hash power, they will find successful hashes MORE OFTEN than the rest of the world. As such, given enough time, they can start at any depth and build replacement blocks knowing that they will eventually pass up the chain everyone else is working on. When they do, the entire network will abandon their own chain and start building on top of this other, now longer, chain. The higher percentage the attacker has, the faster and easier they can pull off the attack, but it becomes mathematically possible as soon as they exceed 50%, therefore it is commonly called a 51% attack.
Note that once a single entity controls more than 50% of the hash power, they can effectively shut out ALL other miners and mine 100% of the blocks. This is because if any miner succeeds in mining a block, the attacker can simply ignore that block (and any blocks on top of it) and continue to build on their own blocks until they pass up the chain the other miner attempted to fork. Since other miners can no longer generate any revenue, they will have no incentive to continue mining and will simply shut off their equipment. This reduces the amount of "other" hash power on the network and makes it even easier for the attacker to maintain their attack (since they now have an even higher percentage of the remaining hash power).
and what a replay attack are?
Ok, lets create a hypothetical situation here...
Let us say that starting immediately after the 460,000
th block in the blockchain 70% of bitcoin users, miners, merchants, nodes, exchanges, hashpower, etc decide they want the maximum allowable blocksize to be 2 megabytes. For clarity, we'll call this "BitcoinNew"
Let us say the other 30% continue to run the old version of bitcoin that had a maximum allowable blocksize of 1 megabyte. For clarity we'll call this software "BitcoinOrig"
Miners using BitcoinNew software will find solutions to blocks 7 times for every 3 times that those using BitcoinOrig software do. However, BitcoinOrig software will not recognize blocks bigger than 1 megabyte as valid, so won't include them in their chain at all no matter how long the chain gets.
So, in this situation, a BitcoinNew miner can build a 1.5 megabyte 460,001
st block, and all the other BitcoinNew miners will build on top of it. All the BitcoinNew users will see and accept these blocks. Meanwhile, BitcoinOrig miners will simply ignore the 1.5 megabyte block as invalid. Since they see it as invalid, they don't recognize any of the blocks on top of it as valid either. Instead, they will build their own 460,001
st block that is 1 megabyte or less.
This means that at the 460,001
st block there will be TWO block rewards. One that is only valid on the BitcoinNew, and another that is only valid on the BitcoinOrig chain. The BitcoinOrig miners won't be able to get those transactions confirmed on the other chain and vice versa.
However, since the fork happened at the 460,001
st block, that means that BOTH BitcoinNew AND BitcoinOrig recognize block number 460,000 (and all the earlier blocks) as being a valid part of their own chain. So if you have any bitcoins that you received in one of those earlier blocks, you can use them and get them confirmed in later blocks in either (or both) of those forks.
This is where the "replay" attack becomes a problem.
Lets say there is a merchant that says he is running BitcoinOrig and only accepts BitcoinOrig transactions. You create a transaction spending bitcoins that you receive before the fork and transmit it to BitcoinOrig peers. It eventually gets confirmed in a new block in the BitcoinOrig fork. So far so good. Except, since that anyone that sees that transaction in the BitcoinOrig fork can now re-broadcast the exact same transaction to a BitcoinNew peer. Since the transaction already has your valid signature on it, it will get relayed across the BitcoinNew network and eventually confirmed in the BitcoinNew even though you only intended to pay a BitcoinOrig with BitcoinOrig coins. The transaction has been "re-played" on the other fork, which is why it's called a "replay attack".
The same can occur going the other way (you send BitcoinNew bitcoins to a BitcoinNew merchant, and someone replays that transaction on the BitcoinOrig network and into the BitcoinOrig fork without your permission.