func CreatePuzzleRC5(t uint64, message []byte, puzzleCreator func(uint64, []byte) (crypto.Puzzle, []byte, error)) (ciphertext []byte, puzzle crypto.Puzzle, err error) {
	// Generate private key
	var key []byte
	if key, err = Generate16ByteKey(rand.Reader); err != nil {
		err = fmt.Errorf("Could not generate rc5 key for puzzle: %s", err)
		return
	}

	if puzzle, key, err = puzzleCreator(t, key); err != nil {
		err = fmt.Errorf("Error while creating timelock puzzle for rc5: %s", err)
		return
	}

	// Create the cipher
	var RC5Cipher cipher.Block
	if RC5Cipher, err = rc5.New(key); err != nil {
		err = fmt.Errorf("Error creating cipher for encryption in rc5 puzzle: %s", err)
		return
	}

	// check to make sure we're going to succeed when encrypting
	if len(message) < RC5Cipher.BlockSize() {
		err = fmt.Errorf("ciphertext less than blocksize, make a bigger ciphertext")
		return
	}

	// Generate random initialization vector
	var iv []byte
	ciphertext = make([]byte, RC5Cipher.BlockSize()+len(message))

	// The IV needs to be unique, but not secure. Therefore it's common to
	// include it at the beginning of the ciphertext.
	iv = ciphertext[:RC5Cipher.BlockSize()]
	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
		err = fmt.Errorf("Error reading random reader for iv: %s", err)
	}

	// Create encrypter
	var cfbEncrypter cipher.Stream
	cfbEncrypter = cipher.NewCFBEncrypter(RC5Cipher, iv)

	// Actually encrypt
	cfbEncrypter.XORKeyStream(ciphertext[RC5Cipher.BlockSize():], message)

	// We've sent out the puzzle (which is n, a, t, ck). We've also sent out cm. This is now consistent with RSW96.

	return
}
// CreatePuzzleRC5 creates a timelock puzzle with time t and encrypts the message using RC5.
CreatePuzzleRC5 creates a timelock puzzle with time t and encrypts the message using RC5.
// CreatePuzzleRC5 creates a timelock puzzle with time t and encrypts the message using RC5 .
func CreatePuzzleRC5(t uint64, message []byte, puzzleCreator func(uint64, []byte) (crypto.Puzzle, []byte, error)) (ciphertext []byte, puzzle crypto.Puzzle, err error) {
	var key []byte
	if key, err = Generate16ByteKey(rand.Reader); err != nil {
		err = fmt.Errorf("Could not generate rc5 key for puzzle: %s", err)
		return
	}
	if puzzle, key, err = puzzleCreator(t, key); err != nil {
		err = fmt.Errorf("Error while creating timelock puzzle for rc5: %s", err)
		return
	}
	var RC5Cipher cipher.Block
	if RC5Cipher, err = rc5.New(key); err != nil {
		err = fmt.Errorf("Error creating cipher for encryption in rc5 puzzle: %s", err)
		return
	}
	if len(message) < RC5Cipher.BlockSize() {
		err = fmt.Errorf("ciphertext less than blocksize, make a bigger ciphertext")
		return
	}
	var iv []byte
	ciphertext = make([]byte, RC5Cipher.BlockSize()+len(message))
	iv = ciphertext[:RC5Cipher.BlockSize()]
	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
		err = fmt.Errorf("Error reading random reader for iv: %s", err)
	}
	var cfbEncrypter cipher.Stream
	cfbEncrypter = cipher.NewCFBEncrypter(RC5Cipher, iv)
	cfbEncrypter.XORKeyStream(ciphertext[RC5Cipher.BlockSize():], message)
	return
}
func CreatePuzzleRC5 ( t uint64 , message [ ] byte , puzzleCreator func ( uint64 , [ ] byte ) ( crypto . Puzzle , [ ] byte , error ) ) ( ciphertext [ ] byte , puzzle crypto . Puzzle , err error ) { var key [ ] byte if key , err = Generate16ByteKey ( rand . Reader ) ; err != nil { err = fmt . Errorf ( " " , err ) return } if puzzle , key , err = puzzleCreator ( t , key ) ; err != nil { err = fmt . Errorf ( " " , err ) return } var RC5Cipher cipher . Block if RC5Cipher , err = rc5 . New ( key ) ; err != nil { err = fmt . Errorf ( " " , err ) return } if len ( message ) < RC5Cipher . BlockSize ( ) { err = fmt . Errorf ( " " ) return } var iv [ ] byte ciphertext = make ( [ ] byte , RC5Cipher . BlockSize ( ) + len ( message ) ) iv = ciphertext [ : RC5Cipher . BlockSize ( ) ] if _ , err := io . ReadFull ( rand . Reader , iv ) ; err != nil { err = fmt . Errorf ( " " , err ) } var cfbEncrypter cipher . Stream cfbEncrypter = cipher . NewCFBEncrypter ( RC5Cipher , iv ) cfbEncrypter . XORKeyStream ( ciphertext [ RC5Cipher . BlockSize ( ) : ] , message ) return }
CreatePuzzleRC5 creates a timelock puzzle with time t and encrypts the message using RC5.
CreatePuzzleRC5 creates a timelock puzzle with time t and encrypts the message using RC5 .
// Generate private key // Create the cipher // check to make sure we're going to succeed when encrypting // Generate random initialization vector // The IV needs to be unique, but not secure. Therefore it's common to // include it at the beginning of the ciphertext. // Create encrypter // Actually encrypt // We've sent out the puzzle (which is n, a, t, ck). We've also sent out cm. This is now consistent with RSW96.