def checksum(data):
    """Creates the ICMP checksum as in RFC 1071

    :param data: Data to calculate the checksum ofs
    :type data: bytes
    :return: Calculated checksum
    :rtype: int

    Divides the data in 16-bits chunks, then make their 1's complement sum"""
    subtotal = 0
    for i in range(0, len(data) - 1, 2):
        subtotal += (data[i] << 8) + data[i + 1]
    if len(data) % 2:
        subtotal += data[len(data) - 1] << 8
    while subtotal >> 16:
        subtotal = (subtotal & 65535) + (subtotal >> 16)
    check = ~subtotal
    return check << 8 & 65280 | check >> 8 & 255
