geocrypt

package module
v0.0.0-...-b45cb54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

README

geocrypt

geocrypt is a cryptographic location hash.

Installation

geocrypt requires a Go installation.

Documentation

http://godoc.org/github.com/kortschak/geocrypt

License

geocrypt is distributed under a modified BSD license.

Documentation

Overview

Package geocrypt implements a geographic cryptographic hash.

Example (Kryptos)
package main

import (
	"fmt"
	"log"

	"github.com/kortschak/geocrypt"
)

func main() {
	lat := 38.9521808
	lon := -77.1458137
	text := "Kryptos"
	prec := 6

	bits := geocrypt.Bits(prec)
	latErr, lonErr := geocrypt.Error(bits)

	fmt.Printf("prec=%d bits=%d error lat=%.2e lon=%.2e\n", prec, bits, latErr, lonErr)

	h, err := geocrypt.Hash(lat, lon, text, prec)
	if err != nil {
		log.Fatal(err)
	}

	// Compare against reduced accuracy location.
	// First without note text.
	fmt.Println(geocrypt.Compare(h, 38.95218, -77.14581, ""))
	// And then with note text.
	fmt.Println(geocrypt.Compare(h, 38.95218, -77.14581, text))

}
Output:


prec=6 bits=48 error lat=1.07e-05 lon=2.15e-05
0 geocrypt: hashedLocation is not the hash of the given location
48 <nil>

Index

Examples

Constants

View Source
const (
	// MinPrecision is the minimum allowable precision
	// that may be passed to Hash and Error.
	MinPrecision = 1

	// MaxPrecision is the maximum allowable precision
	// that may be passed to Hash and Error.
	MaxPrecision = 9

	// DefaultPrecision corresponds to approximately one
	// diagonal metre at the equator.
	DefaultPrecision = 7
)

Variables

View Source
var ErrInvalidPrecision = errors.New("geocrypt: location precision out of range")

The error returned from Hash and Geohash when the precision is out of the valid range.

View Source
var ErrMismatchedHashAndLocation = errors.New("geocrypt: hashedLocation is not the hash of the given location")

The error returned from Compare when a location and hash do not match.

View Source
var ErrTextTooLong = errors.New("geocrypt: note text is too long")

The error returned from Hash or Compare when note text is longer than 64 bytes.

Functions

func Bits

func Bits(prec int) int

Bits returns the geohash bit precision corresponding to the given geocrypt precision.

func Compare

func Compare(hashedLocation []byte, lat, long float64, text string) (bits int, err error)

Compare compares the geocrypt hashed location with the location at latitude and longitude and note text. The note text is appended the the geohash of the location before comparing to the hashed location. It returns the highest number of geohash precision bits in the hash set on success or an error on failure.

func Error

func Error(bits int) (lat, long float64)

Error returns the latitude and longitude error for the given bit precision. It will return NaN when bits is less than one or greater than 60.

func Geohash

func Geohash(lat, long float64, bits int) ([]byte, error)

Geohash returns the geohash for the given latitude and longitude with the given bit precision. The value of bits must not be less than five or greater than 60.

func Hash

func Hash(lat, long float64, text string, precs ...int) ([]byte, error)

Hash returns the geocrypt hash set of the location at the given latitude and longitude and note text with the given precisions. The note text is appended to the geohash of the location before hashing. If no precision is given, DefaultPrecision is used. When more than one precision is given, the hashes are concatenated in order of descending precision.

func Location

func Location(geohash []byte) (lat, long float64, bits int, err error)

Location returns the latitude and longitude for a geohash, along the bit precision of the geohash.

func Prec

func Prec(bits int) int

Prec returns the geocrypt precision corresponding to the given geohash bit precision.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL