Question: I'm working on malware analysis at my university and I'm trying to develop ransomware. I'm planning to publish the source code after it's finished. Is there any open source ransomware sample so I can take a look?

Answer: 
There is an open source ransomware called [Hidden Tear](https://github.com/utkusen/hidden-tear). The code encrypts files with the following extensions: ".txt", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".jpg", ".png", ".csv", ".sql", ".mdb", ".sln", ".php", ".asp", ".aspx", ".html", ".xml", ".psd" by default with AES 256 bit encryption. 

It is open source so it could be easily customized to not only look for additional files but also the way encryption is done.
"[The Zoo](https://github.com/ytisf/theZoo)" is a good source of malware for research, including some ransomware. [This](https://github.com/ytisf/theZoo/tree/master/malwares/Source/Original/Ransomware.Jigsaw), for example, is ransomware:

Modern ransomware does not typically use just a symmetric key or operate via the mode described in some of the other answers. A method of operation more closely related to "real world" ransomware looks like this:

* Generate a unique asymmetric key pair on the ransomware server
* Send the public key to the victim machine for use with ransomware client (already lying in wait on victim machine)
* For each file in list of files to encrypt:
* ... generate random symmetric key (e.g., AES key)
* ... encrypt file with random symmetric key
* ... encrypt symmetric key with asymmetric public key
* ... replace file with symmetric-encrypted file concatenated with public-key-encrypted symmetric key

In this manner, each encrypted file has its own symmetric key encrypted with the unique public-key. Thus the only possibility of recovery is by purchasing the private key, which only exists on the ransomware server.